<!doctype html><html lang="en">
 <head>
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  <title>CSS Spatial Navigation Level 1</title>
  <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
  <meta content="exploring" name="csswg-work-status">
  <meta content="ED" name="w3c-status">
  <meta content="This specification defines a general model for navigating the focus using the arrow keys,      as well as related CSS, JavaScript features and Events." name="abstract">
  <link href="../default.css" rel="stylesheet" type="text/css">
  <link href="../csslogo.ico" rel="shortcut icon" type="image/x-icon">
<style>
  body {
    background: url("https://www.w3.org/StyleSheets/TR/logo-ED") top left no-repeat;
  }
  </style>
  <link href="https://www.w3.org/TR/css-nav-1/" rel="canonical">
<style>
code.key {
    border: solid 1px;
    border-radius: 0.5ch;
    padding: 1px 5px;
}
.output {
    background: white;
    padding: 1em;
}
</style>
<style>
#api-check:checked ~ .api,
#api-check:checked ~ * .api {
	display: none;
}
#cssapi-check:checked ~ .cssapi,
#cssapi-check:checked ~ * .cssapi {
	display: none;
}
#verbose-check:checked ~ .verbose,
#verbose-check:checked ~ * .verbose {
	display: none;
}
</style>
<style>
        #example-cal table, #example-cal td, #example-cal th {
            border-collapse: collapse;
            border: solid 1px;
        }
        #example-cal th { text-align: center; }
        #example-cal td { width: 12.5%; }
        #example-cal {
            display: grid;
            grid-template-columns: auto 1fr auto;
        }
        #example-cal button { align-self: center; }

        /* For browsers that don’t support grid */
        #example-cal table {
            display:inline-table;
            vertical-align: middle;
        }
        </style>
<style>/* style-md-lists */

/* This is a weird hack for me not yet following the commonmark spec
   regarding paragraph and lists. */
[data-md] > :first-child {
    margin-top: 0;
}
[data-md] > :last-child {
    margin-bottom: 0;
}</style>
<style>/* style-selflinks */

.heading, .issue, .note, .example, li, dt {
    position: relative;
}
a.self-link {
    position: absolute;
    top: 0;
    left: calc(-1 * (3.5rem - 26px));
    width: calc(3.5rem - 26px);
    height: 2em;
    text-align: center;
    border: none;
    transition: opacity .2s;
    opacity: .5;
}
a.self-link:hover {
    opacity: 1;
}
.heading > a.self-link {
    font-size: 83%;
}
li > a.self-link {
    left: calc(-1 * (3.5rem - 26px) - 2em);
}
dfn > a.self-link {
    top: auto;
    left: auto;
    opacity: 0;
    width: 1.5em;
    height: 1.5em;
    background: gray;
    color: white;
    font-style: normal;
    transition: opacity .2s, background-color .2s, color .2s;
}
dfn:hover > a.self-link {
    opacity: 1;
}
dfn > a.self-link:hover {
    color: black;
}

a.self-link::before            { content: "¶"; }
.heading > a.self-link::before { content: "§"; }
dfn > a.self-link::before      { content: "#"; }</style>
<style>/* style-counters */

body {
    counter-reset: example figure issue;
}
.issue {
    counter-increment: issue;
}
.issue:not(.no-marker)::before {
    content: "Issue " counter(issue);
}

.example {
    counter-increment: example;
}
.example:not(.no-marker)::before {
    content: "Example " counter(example);
}
.invalid.example:not(.no-marker)::before,
.illegal.example:not(.no-marker)::before {
    content: "Invalid Example" counter(example);
}

figcaption {
    counter-increment: figure;
}
figcaption:not(.no-marker)::before {
    content: "Figure " counter(figure) " ";
}</style>
<style>/* style-var-click-highlighting */

    var { cursor: pointer; }
    var.selected0 { background-color: #F4D200; box-shadow: 0 0 0 2px #F4D200; }
    var.selected1 { background-color: #FF87A2; box-shadow: 0 0 0 2px #FF87A2; }
    var.selected2 { background-color: #96E885; box-shadow: 0 0 0 2px #96E885; }
    var.selected3 { background-color: #3EEED2; box-shadow: 0 0 0 2px #3EEED2; }
    var.selected4 { background-color: #EACFB6; box-shadow: 0 0 0 2px #EACFB6; }
    var.selected5 { background-color: #82DDFF; box-shadow: 0 0 0 2px #82DDFF; }
    var.selected6 { background-color: #FFBCF2; box-shadow: 0 0 0 2px #FFBCF2; }
    </style>
<style>/* style-autolinks */

.css.css, .property.property, .descriptor.descriptor {
    color: #005a9c;
    font-size: inherit;
    font-family: inherit;
}
.css::before, .property::before, .descriptor::before {
    content: "‘";
}
.css::after, .property::after, .descriptor::after {
    content: "’";
}
.property, .descriptor {
    /* Don't wrap property and descriptor names */
    white-space: nowrap;
}
.type { /* CSS value <type> */
    font-style: italic;
}
pre .property::before, pre .property::after {
    content: "";
}
[data-link-type="property"]::before,
[data-link-type="propdesc"]::before,
[data-link-type="descriptor"]::before,
[data-link-type="value"]::before,
[data-link-type="function"]::before,
[data-link-type="at-rule"]::before,
[data-link-type="selector"]::before,
[data-link-type="maybe"]::before {
    content: "‘";
}
[data-link-type="property"]::after,
[data-link-type="propdesc"]::after,
[data-link-type="descriptor"]::after,
[data-link-type="value"]::after,
[data-link-type="function"]::after,
[data-link-type="at-rule"]::after,
[data-link-type="selector"]::after,
[data-link-type="maybe"]::after {
    content: "’";
}

[data-link-type].production::before,
[data-link-type].production::after,
.prod [data-link-type]::before,
.prod [data-link-type]::after {
    content: "";
}

[data-link-type=element],
[data-link-type=element-attr] {
    font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;
    font-size: .9em;
}
[data-link-type=element]::before { content: "<" }
[data-link-type=element]::after  { content: ">" }

[data-link-type=biblio] {
    white-space: pre;
}</style>
<style>/* style-dfn-panel */

.dfn-panel {
    position: absolute;
    z-index: 35;
    height: auto;
    width: -webkit-fit-content;
    width: fit-content;
    max-width: 300px;
    max-height: 500px;
    overflow: auto;
    padding: 0.5em 0.75em;
    font: small Helvetica Neue, sans-serif, Droid Sans Fallback;
    background: #DDDDDD;
    color: black;
    border: outset 0.2em;
}
.dfn-panel:not(.on) { display: none; }
.dfn-panel * { margin: 0; padding: 0; text-indent: 0; }
.dfn-panel > b { display: block; }
.dfn-panel a { color: black; }
.dfn-panel a:not(:hover) { text-decoration: none !important; border-bottom: none !important; }
.dfn-panel > b + b { margin-top: 0.25em; }
.dfn-panel ul { padding: 0; }
.dfn-panel li { list-style: inside; }
.dfn-panel.activated {
    display: inline-block;
    position: fixed;
    left: .5em;
    bottom: 2em;
    margin: 0 auto;
    max-width: calc(100vw - 1.5em - .4em - .5em);
    max-height: 30vh;
}

.dfn-paneled { cursor: pointer; }
</style>
<style>/* style-syntax-highlighting */
pre.idl.highlight { color: #708090; }
.highlight:not(.idl) { background: hsl(24, 20%, 95%); }
code.highlight { padding: .1em; border-radius: .3em; }
pre.highlight, pre > code.highlight { display: block; padding: 1em; margin: .5em 0; overflow: auto; border-radius: 0; }
c-[a] { color: #990055 } /* Keyword.Declaration */
c-[b] { color: #990055 } /* Keyword.Type */
c-[c] { color: #708090 } /* Comment */
c-[d] { color: #708090 } /* Comment.Multiline */
c-[e] { color: #0077aa } /* Name.Attribute */
c-[f] { color: #669900 } /* Name.Tag */
c-[g] { color: #222222 } /* Name.Variable */
c-[k] { color: #990055 } /* Keyword */
c-[l] { color: #000000 } /* Literal */
c-[m] { color: #000000 } /* Literal.Number */
c-[n] { color: #0077aa } /* Name */
c-[o] { color: #999999 } /* Operator */
c-[p] { color: #999999 } /* Punctuation */
c-[s] { color: #a67f59 } /* Literal.String */
c-[t] { color: #a67f59 } /* Literal.String.Single */
c-[u] { color: #a67f59 } /* Literal.String.Double */
c-[cp] { color: #708090 } /* Comment.Preproc */
c-[c1] { color: #708090 } /* Comment.Single */
c-[cs] { color: #708090 } /* Comment.Special */
c-[kc] { color: #990055 } /* Keyword.Constant */
c-[kn] { color: #990055 } /* Keyword.Namespace */
c-[kp] { color: #990055 } /* Keyword.Pseudo */
c-[kr] { color: #990055 } /* Keyword.Reserved */
c-[ld] { color: #000000 } /* Literal.Date */
c-[nc] { color: #0077aa } /* Name.Class */
c-[no] { color: #0077aa } /* Name.Constant */
c-[nd] { color: #0077aa } /* Name.Decorator */
c-[ni] { color: #0077aa } /* Name.Entity */
c-[ne] { color: #0077aa } /* Name.Exception */
c-[nf] { color: #0077aa } /* Name.Function */
c-[nl] { color: #0077aa } /* Name.Label */
c-[nn] { color: #0077aa } /* Name.Namespace */
c-[py] { color: #0077aa } /* Name.Property */
c-[ow] { color: #999999 } /* Operator.Word */
c-[mb] { color: #000000 } /* Literal.Number.Bin */
c-[mf] { color: #000000 } /* Literal.Number.Float */
c-[mh] { color: #000000 } /* Literal.Number.Hex */
c-[mi] { color: #000000 } /* Literal.Number.Integer */
c-[mo] { color: #000000 } /* Literal.Number.Oct */
c-[sb] { color: #a67f59 } /* Literal.String.Backtick */
c-[sc] { color: #a67f59 } /* Literal.String.Char */
c-[sd] { color: #a67f59 } /* Literal.String.Doc */
c-[se] { color: #a67f59 } /* Literal.String.Escape */
c-[sh] { color: #a67f59 } /* Literal.String.Heredoc */
c-[si] { color: #a67f59 } /* Literal.String.Interpol */
c-[sx] { color: #a67f59 } /* Literal.String.Other */
c-[sr] { color: #a67f59 } /* Literal.String.Regex */
c-[ss] { color: #a67f59 } /* Literal.String.Symbol */
c-[vc] { color: #0077aa } /* Name.Variable.Class */
c-[vg] { color: #0077aa } /* Name.Variable.Global */
c-[vi] { color: #0077aa } /* Name.Variable.Instance */
c-[il] { color: #000000 } /* Literal.Number.Integer.Long */
</style>
 <body class="h-entry">
  <div class="head">
   <p data-fill-with="logo"><a class="logo" href="https://www.w3.org/"> <img alt="W3C" height="48" src="https://www.w3.org/StyleSheets/TR/2016/logos/W3C" width="72"> </a> </p>
   <h1 class="p-name no-ref" id="title">CSS Spatial Navigation Level 1</h1>
   <h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Editor’s Draft, <time class="dt-updated" datetime="1970-01-01">1 January 1970</time></span></h2>
   <details>
    <summary>Specification Metadata</summary>
    <div data-fill-with="spec-metadata">
     <dl>
      <dt>This version:
      <dd><a class="u-url" href="https://drafts.csswg.org/css-nav-1/">https://drafts.csswg.org/css-nav-1/</a>
      <dt>Latest published version:
      <dd><a href="https://www.w3.org/TR/css-nav-1/">https://www.w3.org/TR/css-nav-1/</a>
      <dt>Previous Versions:
      <dd><a href="https://www.w3.org/TR/2019/WD-css-nav-1-20190423/" rel="prev">https://www.w3.org/TR/2019/WD-css-nav-1-20190423/</a>
      <dd><a href="https://www.w3.org/TR/2019/WD-css-nav-1-20191126/" rel="prev">https://www.w3.org/TR/2019/WD-css-nav-1-20191126/</a>
      <dt class="editor">Editors:
      <dd class="editor p-author h-card vcard" data-editor-id="79168"><a class="p-name fn u-email email" href="mailto:jh.hong@lge.com">Jihye Hong</a> (<span class="p-org org">LG Electronics</span>)
      <dd class="editor p-author h-card vcard" data-editor-id="43241"><a class="p-name fn u-url url" href="https://florian.rivoal.net">Florian Rivoal</a> (<span class="p-org org">Invited Expert</span>)
      <dt>Suggest an Edit for this Spec:
      <dd><a href="https://github.com/w3c/csswg-drafts/blob/master/css-nav-1/Overview.bs">GitHub Editor</a>
      <dt>Issue Tracking:
      <dd><a href="https://github.com/w3c/csswg-drafts/labels/css-nav-1">GitHub Issues</a>
     </dl>
    </div>
   </details>
   <div data-fill-with="warning"></div>
   <p class="copyright" data-fill-with="copyright"><a href="https://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 1970 <a href="https://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="https://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="https://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="https://www.keio.ac.jp/">Keio</a>, <a href="https://ev.buaa.edu.cn/">Beihang</a>). W3C <a href="https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document">permissive document license</a> rules apply. </p>
   <hr title="Separator for header">
  </div>
  <div class="p-summary" data-fill-with="abstract">
   <h2 class="no-num no-toc no-ref heading settled" id="abstract"><span class="content">Abstract</span></h2>
   <p>This specification defines a general model for navigating the focus using the arrow keys,

    as well as related CSS, JavaScript features and Events.</p>
    <a href="https://www.w3.org/TR/CSS/">CSS</a> is a language for describing the rendering of structured documents
(such as HTML and XML)
on screen, on paper, etc. 
  </div>
  <h2 class="no-num no-toc no-ref heading settled" id="status"><span class="content">Status of this document</span></h2>
  <div data-fill-with="status">
   <p> This is a public copy of the editors’ draft.
	It is provided for discussion only and may change at any moment.
	Its publication here does not imply endorsement of its contents by W3C.
	Don’t cite this document other than as work in progress. </p>
   <p> <a href="https://github.com/w3c/csswg-drafts/issues">GitHub Issues</a> are preferred for discussion of this specification.
	When filing an issue, please put the text “css-nav” in the title,
	preferably like this:
	“[css-nav] <i data-lt>…summary of comment…</i>”.
	All issues and comments are <a href="https://lists.w3.org/Archives/Public/public-css-archive/">archived</a>,
	and there is also a <a href="https://lists.w3.org/Archives/Public/www-style/">historical archive</a>. </p>
   <p> This document was produced by the <a href="https://www.w3.org/Style/CSS/">CSS Working Group</a>. </p>
   <p> This document was produced by a group operating under
	the <a href="https://www.w3.org/Consortium/Patent-Policy/">W3C Patent Policy</a>.
	W3C maintains a <a href="https://www.w3.org/2004/01/pp-impl/32061/status" rel="disclosure">public list of any patent disclosures</a> made in connection with the deliverables of the group;
	that page also includes instructions for disclosing a patent.
	An individual who has actual knowledge of a patent which the individual believes contains <a href="https://www.w3.org/Consortium/Patent-Policy/#def-essential">Essential Claim(s)</a> must disclose the information in accordance with <a href="https://www.w3.org/Consortium/Patent-Policy/#sec-Disclosure">section 6 of the W3C Patent Policy</a>. </p>
   <p> This document is governed by the <a href="https://www.w3.org/2019/Process-20190301/" id="w3c_process_revision">1 March 2019 W3C Process Document</a>. </p>
   <p></p>
  </div>
  <div data-fill-with="at-risk">
   <p>The following features are at-risk, and may be dropped during the CR period: </p>
   <ul>
    <li><code class="idl"><a data-link-type="idl" href="#dom-element-getspatialnavigationcontainer" id="ref-for-dom-element-getspatialnavigationcontainer">getSpatialNavigationContainer()</a></code>
    <li><code class="idl"><a data-link-type="idl" href="#dom-element-focusableareas" id="ref-for-dom-element-focusableareas">focusableAreas()</a></code>
    <li><a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-contain" id="ref-for-propdef-spatial-navigation-contain">spatial-navigation-contain</a>
    <li><a class="css" data-link-type="propdesc" href="#propdef-spatial-navigation-action" id="ref-for-propdef-spatial-navigation-action">spatial-navigation-action: scroll</a>
    <li><a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-function" id="ref-for-propdef-spatial-navigation-function">spatial-navigation-function</a>
   </ul>
   <p>“At-risk” is a W3C Process term-of-art, and does not necessarily imply that the feature is in danger of being dropped or delayed. It means that the WG believes the feature may have difficulty being interoperably implemented in a timely manner, and marking it as such allows the WG to drop the feature if necessary when transitioning to the Proposed Rec stage, without having to publish a new Candidate Rec without the feature first.</p>
  </div>
  <nav data-fill-with="table-of-contents" id="toc">
   <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
   <ol class="toc" role="directory">
    <li><a href="#intro"><span class="secno">1</span> <span class="content"> Introduction</span></a>
    <li><a href="#interaction"><span class="secno">2</span> <span class="content"> Module interaction</span></a>
    <li><a href="#overview"><span class="secno">3</span> <span class="content"> Overview</span></a>
    <li><a href="#triggering"><span class="secno">4</span> <span class="content"> Triggering Spatial Navigation</span></a>
    <li>
     <a href="#js-api"><span class="secno">5</span> <span class="content"> JavaScript API</span></a>
     <ol class="toc">
      <li><a href="#high-level-api"><span class="secno">5.1</span> <span class="content"> Triggering Navigation Programmatically</span></a>
      <li><a href="#low-level-api"><span class="secno">5.2</span> <span class="content"> Low level APIs</span></a>
     </ol>
    <li>
     <a href="#events-navigationevent"><span class="secno">6</span> <span class="content"> Navigation Events</span></a>
     <ol class="toc">
      <li><a href="#interface-focusevent"><span class="secno">6.1</span> <span class="content"> Interface NavigationEvent</span></a>
      <li>
       <a href="#events-nav-type"><span class="secno">6.2</span> <span class="content"> Navigation Event Types</span></a>
       <ol class="toc">
        <li><a href="#event-type-navbeforefocus"><span class="secno">6.2.1</span> <span class="content"> <span><code>navbeforefocus</code></span></span></a>
        <li><a href="#event-type-navnotarget"><span class="secno">6.2.2</span> <span class="content"> <span><code>navnotarget</code></span></span></a>
       </ol>
     </ol>
    <li><a href="#policy-feature"><span class="secno">7</span> <span class="content"> The <span>navigation-override</span> <span>policy-controlled feature</span></span></a>
    <li>
     <a href="#processing-model"><span class="secno">8</span> <span class="content"> Processing Model</span></a>
     <ol class="toc">
      <li><a href="#glossary"><span class="secno">8.1</span> <span class="content"> Glossary</span></a>
      <li><a href="#grouping"><span class="secno">8.2</span> <span class="content"> Groupings of elements</span></a>
      <li><a href="#nav"><span class="secno">8.3</span> <span class="content"> Navigation</span></a>
      <li><a href="#heuristics"><span class="secno">8.4</span> <span class="content"> Focus Navigation Heuristics</span></a>
     </ol>
    <li>
     <a href="#declarative"><span class="secno">9</span> <span class="content"> Controlling spatial navigation through declarative means</span></a>
     <ol class="toc">
      <li><a href="#container"><span class="secno">9.1</span> <span class="content"> Creating additional spatial navigation containers: the <span class="property">spatial-navigation-contain</span> property</span></a>
      <li><a href="#css-property-spatialnavigationaction"><span class="secno">9.2</span> <span class="content"> Controlling the interaction with scrolling: the <span class="property">spatial-navigation-action</span> property</span></a>
      <li><a href="#css-property-spatialnavigationfunction"><span class="secno">9.3</span> <span class="content"> Selecting the navigation algorithm: the <span class="property">spatial-navigation-function</span> property</span></a>
     </ol>
    <li><a href="#scrolling"><span class="secno"></span> <span class="content">Appendix A. Scroll extensions</span></a>
    <li><a href="#privsec"><span class="secno"></span> <span class="content"> Appendix B. Privacy and Security Considerations</span></a>
    <li><a href="#ack"><span class="secno"></span> <span class="content">Acknowledgements</span></a>
    <li><a href="#changes"><span class="secno"></span> <span class="content">Changes</span></a>
    <li>
     <a href="#conformance"><span class="secno"></span> <span class="content"> Conformance</span></a>
     <ol class="toc">
      <li><a href="#document-conventions"><span class="secno"></span> <span class="content"> Document conventions</span></a>
      <li><a href="#conform-classes"><span class="secno"></span> <span class="content"> Conformance classes</span></a>
      <li>
       <a href="#conform-responsible"><span class="secno"></span> <span class="content"> Requirements for Responsible Implementation of CSS</span></a>
       <ol class="toc">
        <li><a href="#conform-partial"><span class="secno"></span> <span class="content"> Partial Implementations</span></a>
        <li><a href="#conform-future-proofing"><span class="secno"></span> <span class="content"> Implementations of Unstable and Proprietary Features</span></a>
        <li><a href="#conform-testing"><span class="secno"></span> <span class="content"> Implementations of CR-level Features</span></a>
       </ol>
     </ol>
    <li>
     <a href="#index"><span class="secno"></span> <span class="content">Index</span></a>
     <ol class="toc">
      <li><a href="#index-defined-here"><span class="secno"></span> <span class="content">Terms defined by this specification</span></a>
      <li><a href="#index-defined-elsewhere"><span class="secno"></span> <span class="content">Terms defined by reference</span></a>
     </ol>
    <li>
     <a href="#references"><span class="secno"></span> <span class="content">References</span></a>
     <ol class="toc">
      <li><a href="#normative"><span class="secno"></span> <span class="content">Normative References</span></a>
      <li><a href="#informative"><span class="secno"></span> <span class="content">Informative References</span></a>
     </ol>
    <li><a href="#property-index"><span class="secno"></span> <span class="content">Property Index</span></a>
    <li><a href="#idl-index"><span class="secno"></span> <span class="content">IDL Index</span></a>
    <li><a href="#issues-index"><span class="secno"></span> <span class="content">Issues Index</span></a>
   </ol>
  </nav>
  <main>
   <p>This specification is rather long.
To make it easier to read and focus on a particular area,
a few checkboxes are provided below.
Checking them hides part of the specification.
This is only meant as a reading aid,
the specification remains the full document.</p>
   <input id="api-check" type="checkbox">
   <label for="api-check">Hide JavaScript APIs, including events</label>
   <br> 
   <input id="cssapi-check" type="checkbox">
   <label for="cssapi-check">Hide CSS properties that enable selecting behavior variants, and related information</label>
   <br> 
   <input id="verbose-check" type="checkbox">
   <label for="verbose-check">Hide informative sections that explain and summarize normative sections without adding more information</label>
   <br> 
   <h2 class="non-normative heading settled" data-level="1" id="intro"><span class="secno">1. </span><span class="content"> Introduction</span><a class="self-link" href="#intro"></a></h2>
   <p><em>This section is not normative.</em></p>
   <p>Historically, most browsers have not offered features to let the user move the focus directionally.
Some, such as TV browsers, have enabled the user to move the focus using the arrow keys out of necessity,
since no other input mechanism is available on a typical TV remote control.</p>
   <p>Others have enabled different key combinations to control spatial navigation,
such as pressing the <code class="key">Shift</code> key together with arrow keys.</p>
   <p>This ability to move around the page directionally is called <dfn class="dfn-paneled" data-dfn-type="dfn" data-export data-lt="spatial navigation | spatialNavigation" id="spatial-navigation">spatial navigation</dfn>.</p>
   <p><a data-link-type="dfn" href="#spatial-navigation" id="ref-for-spatial-navigation">Spatial navigation</a> can be useful for a web page built using a grid-like layout,
or other predominantly non linear layouts.
The figure below represents a photo gallery arranged in a grid layout.
If the user presses the <code class="key">Tab</code> key to move focus around the images,
they need to press the key many times to reach the desired image element.</p>
   <figure>
     <img alt="When elements are laid out in a grid pattern, spatial navigation makes it much easier to predict and control where focus should move to." src="images/gallery-app.png" style="width: 500px;"> 
    <figcaption>Photo gallery application example using a grid layout</figcaption>
   </figure>
   <p>Also, <a data-link-type="dfn" href="#spatial-navigation" id="ref-for-spatial-navigation①">spatial navigation</a> moves the focus to the predictable element for users
because it moves the focus among focusable elements depending on their position.
Sometimes elements on the page aren’t arranged independently of their source order.
Therefore unlike <span id="ref-for-spatial-navigation②">spatial navigation</span>, sequential navigation using the <code class="key">Tab</code> key makes focus navigation unpredictable.</p>
   <p>While arrow keys are naturally suited to control spatial navigation,
no previous specification describes how that should work,
or how it may be controlled. <span class="api">This specification introduces a processing model for spatial navigation,
as well as APIs
enabling the author to control and override how spatial navigation works.</span></p>
   <p class="note" role="note"><span>Note:</span> Some aspects of this specification, such as the JavaScript Events and APIs
could also be extended to sequential navigation,
in order to make sure that keyboard navigation has a consistent and well defined model in general.</p>
   <p class="note" role="note"><span>Note:</span> As a general principle,
keyboard navigation,
and spatial navigation in particular,
should be possible to use and control without JavaScript<span class="cssapi">,
and declarative solutions are therefore preferred.
Since spatial navigation depends on layout,
that means CSS is typically the right mechanism to define
spatial navigation related controls</span>. <span class="api">However, in the spirit of the <a href="https://github.com/extensibleweb/manifesto">Extensible Web Manifesto</a> <a data-link-type="biblio" href="#biblio-extensible">[EXTENSIBLE]</a>,
we feel it is important to provide the right JavaScript primitives
to let the author experiment and explore the problem space.
More declarative features may be added later,
based on feedback and experience acquired through such JavaScript usage.</span></p>
   <p class="note" role="note"><span>Note:</span> A few features are marked <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="at-risk">at-risk</dfn>.
The editors of this specification believe
they represent an important part of the user or author experience
of the features defined in the specification.
At the same time, the core functionality of this specification
can be implemented without implementing these
so it seems possible that implementers may choose to down-prioritize them
to reduce the scope of the first implementation.
While it is hoped that these features will be implemented as well,
they are marked at-risk in recognition that they might not be at first.</p>
   <h2 class="heading settled" data-level="2" id="interaction"><span class="secno">2. </span><span class="content"> Module interaction</span><a class="self-link" href="#interaction"></a></h2>
   <p>This document depends on the Infra Standard <a data-link-type="biblio" href="#biblio-infra">[infra]</a>.</p>
   <p>The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" are to be interpreted as described in RFC 2119. <a data-link-type="biblio" href="#biblio-rfc2119">[RFC2119]</a></p>
   <div class="verbose">
    <h2 class="non-normative heading settled" data-level="3" id="overview"><span class="secno">3. </span><span class="content"> Overview</span><a class="self-link" href="#overview"></a></h2>
    <p><em>This section is not normative.</em></p>
    <p>Using a UA-defined mechanism
(typically arrow keys, possibly in combination with modifier keys like <code class="key">Shift</code> or <code class="key">Control</code>),
the user may ask the User Agent to navigate in a particular direction.
This will either
move the focus from its current location to a new focusable item in the direction requested,
or scroll if there is no appropriate item.</p>
    <p>More specifically,
the User Agent will first search for visible and focusable items
in the direction indicated
within the current <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers">spatial navigation container</a> (<span class="cssapi">by default, </span>the root element, scrollable elements, and iframes<span class="cssapi">,
but other elements can be made into <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers①">spatial navigation containers</a> using the <a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-contain" id="ref-for-propdef-spatial-navigation-contain①">spatial-navigation-contain</a> property</span>).</p>
    <p>If it finds any, it will pick the best one for that direction,
and move the focus there.</p>
    <p>If it does not, it will scroll the <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers②">spatial navigation container</a> in the requested direction
instead of moving focus.
Doing so may uncover focusable elements
which would then be eligible targets to move the focus to
next time spatial navigation in the same direction is requested.</p>
    <p>If the <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers③">spatial navigation container</a> cannot be scrolled,
either because it is not a scrollable element
or because it is already scrolled to the maximum in that direction,
the User Agent will select the next <span id="ref-for-spatial-navigation-containers④">spatial navigation container</span> up the ancestry chain,
and recursively repeat the above process
until it finds some element to focus or scroll,
or reaches the root element.</p>
    <p class="note" role="note"><span>Note:</span> As a consequence of this processing model,
the elements that are reachable by sequential navigation
and by spatial navigation are almost the same.
Elements that are currently outside of the viewport of a scrollable element
can only be reached by spatial navigation once they have been scrolled into view.
Therefore, elements that cannot be scrolled into view by default.</p>
    <div class="api">
      At key points during this search for the appropriate response to the spatial navigation request,
the User Agent will fire events.
These enable the author to prevent the upcoming action
(by calling <code class="idl"><a data-link-type="idl" href="https://dom.spec.whatwg.org/#dom-event-preventdefault" id="ref-for-dom-event-preventdefault">preventDefault()</a></code>),
and if desired to provide an alternate action,
such as using the <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/interaction.html#dom-focus" id="ref-for-dom-focus">focus()</a></code> method on a different
element of the author’s choosing. 
     <p>To help the author write such alternate actions,
and as part of exposing underlying platform primitives as per the <a href="https://github.com/extensibleweb/manifesto">Extensible Web</a> principles,
this specification also defines JavaScript APIs
that expose key constructs of the underlying model.</p>
     <p>See <a href="#js-api">§ 5 JavaScript API</a> for details about the JavaScript API, <a href="#events-nav-type">§ 6.2 Navigation Event Types</a> for details about the various events,
and <a href="#declarative">§ 9 Controlling spatial navigation through declarative means</a> for details about the CSS properties.</p>
    </div>
    <div class="example" id="example-8205e5a4">
     <a class="self-link" href="#example-8205e5a4"></a> This example shows how a series of focusable elements
    arranged in a scrollable element
    would be navigated when using spatial navigation.
    For the sake of keeping the description simple,
    this example assumes a User Agent where spatial navigation is triggered using arrow keys. 
     <figure>
       <img alt src="images/spatnav-scroll-visible-1.png" style="width: 200px;"> <img alt src="images/spatnav-scroll-visible-2.png" style="width: 200px;"> 
      <figcaption>Moving focus to the visible element in the <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers⑤">spatial navigation container</a>.</figcaption>
     </figure>
     <p>On the left of figure 2, "Box 2" is focused.
    Pressing the <code class="key">ArrowDown</code> key moves the focus to
    "Box 3" without scrolling because "Box 3" is visible in the <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scrollport" id="ref-for-scrollport">scrollport</a> of the <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers⑥">spatial navigation container</a>.</p>
     <figure>
       <img alt src="images/spatnav-scroll-invisible-1.png" style="width: 160px;"> <img alt src="images/spatnav-scroll-invisible-2.png" style="width: 160px;"> <img alt src="images/spatnav-scroll-invisible-3.png" style="width: 160px;"> <img alt src="images/spatnav-scroll-invisible-4.png" style="width: 160px;"> 
      <figcaption>Moving focus to the hidden element in the <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers⑦">spatial navigation container</a>.</figcaption>
     </figure>
     <p>On the first of figure 3, under "Box 3", there isn’t any visible element in the <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scrollport" id="ref-for-scrollport①">scrollport</a>.
    Therefore, the effect of pressing the <code class="key">ArrowDown</code> is to scroll down, as shown in the second.
    The next press of the <code class="key">ArrowDown</code> key makes "Box 4" come into the <span id="ref-for-scrollport②">scrollport</span>,
    and the focus will move to it when there is additional pressing the <code class="key">ArrowDown</code>, as the fourth.</p>
     <p>This example uses the markup as follows:</p>
<pre class="lang-css highlight"><c- f>#scroller </c-><c- p>{</c->
    <c- k>width</c-><c- p>:</c-> <c- m>700</c-><c- l>px</c-><c- p>;</c->
    <c- k>height</c-><c- p>:</c-> <c- m>700</c-><c- l>px</c-><c- p>;</c->
    <c- k>overflow-x</c-><c- p>:</c-> hidden<c- p>;</c->
    <c- k>overflow-y</c-><c- p>:</c-> auto<c- p>;</c->
<c- p>}</c->

<c- f>.box </c-><c- p>{</c->
    <c- k>width</c-><c- p>:</c-> <c- m>150</c-><c- l>px</c-><c- p>;</c->
    <c- k>height</c-><c- p>:</c-> <c- m>110</c-><c- l>px</c-><c- p>;</c->
    <c- k>background-color</c-><c- p>:</c-> blue<c- p>;</c->
<c- p>}</c->

<c- f>.box:focus </c-><c- p>{</c->
    <c- k>background-color</c-><c- p>:</c-> red<c- p>;</c->
<c- p>}</c->
</pre>
<pre class="lang-html highlight"><c- p>&lt;</c-><c- f>div</c-> <c- e>id</c-><c- o>=</c-><c- s>"scroller"</c-><c- p>></c->
    <c- p>&lt;</c-><c- f>div</c-> <c- e>class</c-><c- o>=</c-><c- s>"box"</c-> <c- e>tabindex</c-><c- o>=</c-><c- s>"0"</c-><c- p>></c->Box 1<c- p>&lt;/</c-><c- f>div</c-><c- p>></c->
    <c- p>&lt;</c-><c- f>div</c-> <c- e>class</c-><c- o>=</c-><c- s>"box"</c-> <c- e>tabindex</c-><c- o>=</c-><c- s>"0"</c-><c- p>></c->Box 2<c- p>&lt;/</c-><c- f>div</c-><c- p>></c->
    <c- p>&lt;</c-><c- f>div</c-> <c- e>class</c-><c- o>=</c-><c- s>"box"</c-> <c- e>tabindex</c-><c- o>=</c-><c- s>"0"</c-><c- p>></c->Box 3<c- p>&lt;/</c-><c- f>div</c-><c- p>></c->
    <c- p>&lt;</c-><c- f>div</c-> <c- e>class</c-><c- o>=</c-><c- s>"box"</c-> <c- e>tabindex</c-><c- o>=</c-><c- s>"0"</c-><c- p>></c->Box 4<c- p>&lt;/</c-><c- f>div</c-><c- p>></c->
<c- p>&lt;/</c-><c- f>div</c-><c- p>></c->
</pre>
    </div>
   </div>
   <h2 class="heading settled" data-level="4" id="triggering"><span class="secno">4. </span><span class="content"> Triggering Spatial Navigation</span><a class="self-link" href="#triggering"></a></h2>
   <p>When the user triggers spatial navigation in a given direction,
the User Agent must run the <a data-link-type="dfn" href="#spatial-navigation-steps" id="ref-for-spatial-navigation-steps">spatial navigation steps</a> in that direction.</p>
   <p>This specification does not define what UI mechanism User Agents should offer to users to trigger spatial navigation.
This intentionally left for User Agents to decide.</p>
   <div class="note" role="note">Note:
    It is expected that User Agents on devices with limited input capabilities,
    such as TVs operated with a remote control,
    feature phones,
    or devices operated with a game controller,
    will use spatial navigation as their primary or exclusive navigation mechanism. </div>
   <p>Although User Agents can implement the processing model and APIs
defined by the specification,
this specification recommends that
User Agents should offer a means for users to trigger spatial navigation directly,
without having to use the APIs.</p>
   <p class="note" role="note"><span>Note:</span> Conversely, the author should assume that spatial navigation may be triggered
by the User Agent in response to user actions
even if the author has not invoked any of the APIs.</p>
   <p>Regardless of the actual mechanism chosen to trigger spatial navigation,
the following requirements apply:</p>
   <ul>
    <li data-md>
     <p>If the mechanism the user must use to trigger spatial navigation
would normally fire a <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/uievents/#uievent" id="ref-for-uievent">UIEvent</a></code>,
the event must be fired prior to running the <a data-link-type="dfn" href="#spatial-navigation-steps" id="ref-for-spatial-navigation-steps①">spatial navigation steps</a> and these steps must not be run if that event’s <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#canceled-flag" id="ref-for-canceled-flag">canceled flag</a> gets set.</p>
     <div class="example" id="example-71b5d5f5">
      <a class="self-link" href="#example-71b5d5f5"></a> Gaming devices may trigger spatial navigation based on pressing the D-pad.
    This would result in firing a <a class="idl-code" data-link-type="event" href="https://w3c.github.io/uievents/#keydown" id="ref-for-keydown">keydown</a> event
    with the key set to one of <code class="key">ArrowDown</code>, <code class="key">ArrowLeft</code>, <code class="key">ArrowRight</code>,
    or <code class="key">ArrowUp</code>,
    followed if not canceled by running the <a data-link-type="dfn" href="#spatial-navigation-steps" id="ref-for-spatial-navigation-steps②">spatial navigation steps</a><span class="api">,
    including firing the relevant <code class="idl"><a data-link-type="idl" href="#navigationevent" id="ref-for-navigationevent">NavigationEvent</a></code>s</span>. 
      <p>A User Agent on a desktop computer that triggers spatial navigation
    using the arrow keys of the keyboard
    would follow the same sequence.</p>
     </div>
    <li data-md>
     <p>If the mechanism the user must use to trigger spatial navigation
would also perform other actions in some contexts,
the User Agents should in these contexts
give priority to these other actions
and execute them instead of spatial navigation.
It must not trigger both.</p>
     <div class="example" id="example-2ce7f9b0"><a class="self-link" href="#example-2ce7f9b0"></a> In a User Agent that triggers spatial navigation
    using the arrow keys without modifier keys,
    and uses these same arrow keys to move
    the text insertion caret when an editable element is focused,
    the arrow keys should by default to moving the caret.
    Spatial navigation would only be triggered by the arrow keys
    when the focused element is not editable
    or when it is editable, but the caret cannot move any further in the requested direction. </div>
     <p>An exception is made for scrolling:
since spatial navigation itself handles scrolling
(in addition to moving the focus)
User Agents should not offer the same mechanism to trigger both spatial navigation
and the scrolling behavior separate from spatial navigation.
However, User Agents may offer a way for the user to switch between different modes,
or offer both based on different UI mechanisms.</p>
     <div class="example" id="example-812cd513"><a class="self-link" href="#example-812cd513"></a> A User Agent may have a setting to let the user choose
    between using the arrow keys without modifier keys
    for spatial navigation or for scrolling.
    Another one may offer scrolling on arrow keys without modifiers,
    and spatial navigation on arrow keys when pressed together
    with the <code class="key">Shift</code> key,
    or on the <code class="key">W</code> <code class="key">A</code> <code class="key">S</code> <code class="key">D</code> keys.
    Offering only spatial navigation or only scrolling
    as responses to pressing arrow keys would also be possibilities. </div>
   </ul>
   <div class="api">
    <h2 class="heading settled" data-level="5" id="js-api"><span class="secno">5. </span><span class="content"> JavaScript API</span><a class="self-link" href="#js-api"></a></h2>
    <h3 class="heading settled" data-level="5.1" id="high-level-api"><span class="secno">5.1. </span><span class="content"> Triggering Navigation Programmatically</span><a class="self-link" href="#high-level-api"></a></h3>
    <p>The <code class="idl"><a data-link-type="idl" href="#dom-window-navigate" id="ref-for-dom-window-navigate">navigate()</a></code> method enables the author to trigger spatial navigation programmatically,
as if the user had done so manually
(for instance, by pressing the arrow keys in a browser where that is the way to trigger spatial navigation).</p>
    <p class="note" role="note"><span>Note:</span> As this triggers the same processing model as manual navigation,
all the same results should be expected:
the same chain of events will be fired and
the same element will be scrolled or focused.</p>
    <p class="note" role="note"><span>Note:</span> The author can use this to trigger spatial navigation
based on a different UI mechanism than the one assigned by the User Agent,
such as mapping to different keys,
or triggering spatial navigation from a clickable on-screen directional pad,
or in reaction to other events than UI ones.
It could also be used when an author wants to interrupt navigation to do some asynchronous operation
(e.g. load more content in an infinite scroller) then resume the navigation where they canceled.</p>
    <p class="note" role="note"><span>Note:</span> This API is also useful for testing purposes,
as there it is difficult to trigger spatial navigation
that does not depend on vendor specific UI conventions.</p>
<pre class="idl highlight def"><c- b>enum</c-> <dfn class="dfn-paneled idl-code" data-dfn-type="enum" data-export id="enumdef-spatialnavigationdirection"><code><c- g>SpatialNavigationDirection</c-></code></dfn> {
    <dfn class="dfn-paneled idl-code" data-dfn-for="SpatialNavigationDirection" data-dfn-type="enum-value" data-export id="dom-spatialnavigationdirection-up"><code><c- s>"up"</c-></code></dfn>,
    <dfn class="dfn-paneled idl-code" data-dfn-for="SpatialNavigationDirection" data-dfn-type="enum-value" data-export id="dom-spatialnavigationdirection-down"><code><c- s>"down"</c-></code></dfn>,
    <dfn class="dfn-paneled idl-code" data-dfn-for="SpatialNavigationDirection" data-dfn-type="enum-value" data-export id="dom-spatialnavigationdirection-left"><code><c- s>"left"</c-></code></dfn>,
    <dfn class="dfn-paneled idl-code" data-dfn-for="SpatialNavigationDirection" data-dfn-type="enum-value" data-export id="dom-spatialnavigationdirection-right"><code><c- s>"right"</c-></code></dfn>,
};

<c- b>partial</c-> <c- b>interface</c-> <a class="idl-code" data-link-type="interface" href="https://html.spec.whatwg.org/multipage/window-object.html#window" id="ref-for-window"><c- g>Window</c-></a> {
    <c- b>void</c-> <a class="idl-code" data-link-type="method" href="#dom-window-navigate" id="ref-for-dom-window-navigate①"><c- g>navigate</c-></a>(<a class="n" data-link-type="idl-name" href="#enumdef-spatialnavigationdirection" id="ref-for-enumdef-spatialnavigationdirection"><c- n>SpatialNavigationDirection</c-></a> <dfn class="idl-code" data-dfn-for="Window/navigate(dir)" data-dfn-type="argument" data-export id="dom-window-navigate-dir-dir"><code><c- g>dir</c-></code><a class="self-link" href="#dom-window-navigate-dir-dir"></a></dfn>);
};
</pre>
    <div class="algorithm" data-algorithm="windowNavigate steps">
      When the <dfn class="dfn-paneled idl-code" data-dfn-for="Window" data-dfn-type="method" data-export id="dom-window-navigate"><code>navigate(dir)</code></dfn> method is called,
the User Agent must run the following step: 
     <ul>
      <li data-md>
       <p>If direction <var>dir</var> is <code>"up"</code>, <code>"down"</code>, <code>"left"</code>, or <code>"right"</code>,
run the <a data-link-type="dfn" href="#spatial-navigation-steps" id="ref-for-spatial-navigation-steps③">spatial navigation steps</a> in <var>dir</var>.</p>
     </ul>
     <p class="issue" id="issue-a5a227c8"><a class="self-link" href="#issue-a5a227c8"></a> The name of this API is under discussion <a href="https://github.com/w3c/csswg-drafts/issues/3387">&lt;https://github.com/w3c/csswg-drafts/issues/3387></a></p>
    </div>
    <h3 class="heading settled" data-level="5.2" id="low-level-api"><span class="secno">5.2. </span><span class="content"> Low level APIs</span><a class="self-link" href="#low-level-api"></a></h3>
    <p>These APIs are designed to be low level constructs following the processing model closely.
As such, they should be easy to use by the author who wants to extend or override the way spatial navigation works.</p>
<pre class="idl highlight def"><c- b>enum</c-> <dfn class="dfn-paneled idl-code" data-dfn-type="enum" data-export id="enumdef-focusableareasearchmode"><code><c- g>FocusableAreaSearchMode</c-></code></dfn> {
    <dfn class="idl-code" data-dfn-for="FocusableAreaSearchMode" data-dfn-type="enum-value" data-export id="dom-focusableareasearchmode-visible"><code><c- s>"visible"</c-></code><a class="self-link" href="#dom-focusableareasearchmode-visible"></a></dfn>,
    <dfn class="idl-code" data-dfn-for="FocusableAreaSearchMode" data-dfn-type="enum-value" data-export id="dom-focusableareasearchmode-all"><code><c- s>"all"</c-></code><a class="self-link" href="#dom-focusableareasearchmode-all"></a></dfn>
};

<c- b>dictionary</c-> <dfn class="dfn-paneled idl-code" data-dfn-type="dictionary" data-export id="dictdef-focusableareasoption"><code><c- g>FocusableAreasOption</c-></code></dfn> {
    <a class="n" data-link-type="idl-name" href="#enumdef-focusableareasearchmode" id="ref-for-enumdef-focusableareasearchmode"><c- n>FocusableAreaSearchMode</c-></a> <dfn class="dfn-paneled idl-code" data-dfn-for="FocusableAreasOption" data-dfn-type="dict-member" data-export data-type="FocusableAreaSearchMode " id="dom-focusableareasoption-mode"><code><c- g>mode</c-></code></dfn>;
};

<c- b>dictionary</c-> <dfn class="dfn-paneled idl-code" data-dfn-type="dictionary" data-export id="dictdef-spatialnavigationsearchoptions"><code><c- g>SpatialNavigationSearchOptions</c-></code></dfn> {
    <c- b>sequence</c->&lt;<a class="n" data-link-type="idl-name" href="https://dom.spec.whatwg.org/#node" id="ref-for-node"><c- n>Node</c-></a>>? <dfn class="dfn-paneled idl-code" data-dfn-for="SpatialNavigationSearchOptions" data-dfn-type="dict-member" data-export data-type="sequence<Node>? " id="dom-spatialnavigationsearchoptions-candidates"><code><c- g>candidates</c-></code></dfn>;
    <a class="n" data-link-type="idl-name" href="https://dom.spec.whatwg.org/#node" id="ref-for-node①"><c- n>Node</c-></a>? <dfn class="dfn-paneled idl-code" data-dfn-for="SpatialNavigationSearchOptions" data-dfn-type="dict-member" data-export data-type="Node? " id="dom-spatialnavigationsearchoptions-container"><code><c- g>container</c-></code></dfn>;
};

<c- b>partial</c-> <c- b>interface</c-> <a class="idl-code" data-link-type="interface" href="https://dom.spec.whatwg.org/#element" id="ref-for-element"><c- g>Element</c-></a> {
    <a class="n" data-link-type="idl-name" href="https://dom.spec.whatwg.org/#node" id="ref-for-node②"><c- n>Node</c-></a> <a class="idl-code" data-link-type="method" href="#dom-element-getspatialnavigationcontainer" id="ref-for-dom-element-getspatialnavigationcontainer①"><c- g>getSpatialNavigationContainer</c-></a>();
    <c- b>sequence</c->&lt;<a class="n" data-link-type="idl-name" href="https://dom.spec.whatwg.org/#node" id="ref-for-node③"><c- n>Node</c-></a>> <a class="idl-code" data-link-type="method" href="#dom-element-focusableareas" id="ref-for-dom-element-focusableareas①"><c- g>focusableAreas</c-></a>(<c- b>optional</c-> <a class="n" data-link-type="idl-name" href="#dictdef-focusableareasoption" id="ref-for-dictdef-focusableareasoption"><c- n>FocusableAreasOption</c-></a> <dfn class="idl-code" data-dfn-for="Element/focusableAreas(option), Element/focusableAreas()" data-dfn-type="argument" data-export id="dom-element-focusableareas-option-option"><code><c- g>option</c-></code><a class="self-link" href="#dom-element-focusableareas-option-option"></a></dfn>);
    <a class="n" data-link-type="idl-name" href="https://dom.spec.whatwg.org/#node" id="ref-for-node④"><c- n>Node</c-></a>? <dfn class="dfn-paneled idl-code" data-dfn-for="Element" data-dfn-type="method" data-export data-lt="spatialNavigationSearch(dir, options)|spatialNavigationSearch(dir)" id="dom-element-spatialnavigationsearch"><code><c- g>spatialNavigationSearch</c-></code></dfn>(<a class="n" data-link-type="idl-name" href="#enumdef-spatialnavigationdirection" id="ref-for-enumdef-spatialnavigationdirection①"><c- n>SpatialNavigationDirection</c-></a> <dfn class="idl-code" data-dfn-for="Element/spatialNavigationSearch(dir, options), Element/spatialNavigationSearch(dir)" data-dfn-type="argument" data-export id="dom-element-spatialnavigationsearch-dir-options-dir"><code><c- g>dir</c-></code><a class="self-link" href="#dom-element-spatialnavigationsearch-dir-options-dir"></a></dfn>, <c- b>optional</c-> <a class="n" data-link-type="idl-name" href="#dictdef-spatialnavigationsearchoptions" id="ref-for-dictdef-spatialnavigationsearchoptions"><c- n>SpatialNavigationSearchOptions</c-></a> <dfn class="idl-code" data-dfn-for="Element/spatialNavigationSearch(dir, options), Element/spatialNavigationSearch(dir)" data-dfn-type="argument" data-export id="dom-element-spatialnavigationsearch-dir-options-options"><code><c- g>options</c-></code><a class="self-link" href="#dom-element-spatialnavigationsearch-dir-options-options"></a></dfn>);
};
</pre>
    <p class="note" role="note"><span>Note:</span> The way the direction is expressed allows us to expand to more than 4-way navigation
later if this is found necessary.
More directional keywords or a numerical angle could be added.</p>
    <p class="note" role="note"><span>Note:</span> the <code class="idl"><a data-link-type="idl" href="#dom-element-focusableareas" id="ref-for-dom-element-focusableareas②">focusableAreas()</a></code> and <code class="idl"><a data-link-type="idl" href="#dom-element-getspatialnavigationcontainer" id="ref-for-dom-element-getspatialnavigationcontainer②">getSpatialNavigationContainer()</a></code> methods are <a data-link-type="dfn" href="#at-risk" id="ref-for-at-risk">at-risk</a>.</p>
    <p>When these methods are called,
the User Agent must run the steps described below:</p>
    <div class="algorithm" data-algorithm="getSpatialNavigationContainer steps">
     <dl>
      <dt data-md><dfn class="dfn-paneled idl-code" data-dfn-for="Element" data-dfn-type="method" data-export id="dom-element-getspatialnavigationcontainer"><code>getSpatialNavigationContainer()</code></dfn>
      <dd data-md>
       <ol>
        <li data-md>
         <p>Return the nearest ancestor of the element that is a <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers⑧">spatial navigation container</a>,
or the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-document" id="ref-for-concept-document">document</a> if the nearest <span id="ref-for-spatial-navigation-containers⑨">spatial navigation container</span> is the viewport.</p>
       </ol>
       <p class="note" role="note"><span>Note:</span> If the element is a <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers①⓪">spatial navigation container</a>, <code class="idl"><a data-link-type="idl" href="#dom-element-getspatialnavigationcontainer" id="ref-for-dom-element-getspatialnavigationcontainer③">getSpatialNavigationContainer()</a></code> also returns
the nearest <span id="ref-for-spatial-navigation-containers①①">spatial navigation container</span>, not the element itself.</p>
     </dl>
    </div>
    <div class="algorithm" data-algorithm="focusableAreas steps">
     <dl>
      <dt data-md><dfn class="dfn-paneled idl-code" data-dfn-for="Element" data-dfn-type="method" data-export data-lt="focusableAreas(option)|focusableAreas()" id="dom-element-focusableareas"><code>focusableAreas(<var>option</var>)</code></dfn>
      <dd data-md>
       <ol>
        <li data-md>
         <p>Let <var>visibleOnly</var> be <code>false</code> if <var>option</var> is present and its value is equal to <code><a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css-cascade-4/#propdef-all" id="ref-for-propdef-all">all</a></code>,
or <code>true</code> otherwise.</p>
        <li data-md>
         <p>Let <var>areas</var> be the result of <a data-link-type="dfn" href="#find-focusable-areas" id="ref-for-find-focusable-areas">finding focusable areas</a> within the element with <var>visibleOnly</var> as argument.</p>
        <li data-md>
         <p>Return <var>areas</var></p>
       </ol>
     </dl>
    </div>
    <div class="example" id="focusAreas-visible">
     <a class="self-link" href="#focusAreas-visible"></a> The following code shows how to get all the visible focusable elements in the current page using <code class="idl"><a data-link-type="idl" href="#dom-element-focusableareas" id="ref-for-dom-element-focusableareas③">focusableAreas()</a></code>.
    If the method finds a <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers①②">spatial navigation container</a>, it recursively finds focusable areas inside it.
    Because the value of the <code class="idl"><a data-link-type="idl" href="#dom-focusableareasoption-mode" id="ref-for-dom-focusableareasoption-mode">mode</a></code> attribute in this method is <code>visible</code>,
    the focusable elements which aren’t inside the <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scrollport" id="ref-for-scrollport③">scrollport</a> are excluded from the result. 
<pre><code class="highlight"><c- p>&lt;</c-><c- f>body</c-><c- p>></c->
    <c- p>&lt;</c-><c- f>button</c-><c- p>>&lt;/</c-><c- f>button</c-><c- p>></c->
    <c- p>&lt;</c-><c- f>div</c-> <c- e>style</c-><c- o>=</c-><c- s>"width:300px; height:200px; overflow-x: scroll;"</c-><c- p>></c->
        <c- p>&lt;</c-><c- f>button</c-> <c- e>style</c-><c- o>=</c-><c- s>"left:25px;"</c-><c- p>>&lt;/</c-><c- f>button</c-><c- p>></c->
        <c- p>&lt;</c-><c- f>button</c-> <c- e>style</c-><c- o>=</c-><c- s>"left:150px;"</c-><c- p>>&lt;/</c-><c- f>button</c-><c- p>></c->
        <c- p>&lt;</c-><c- f>button</c-> <c- e>style</c-><c- o>=</c-><c- s>"left:350px;"</c-><c- p>>&lt;/</c-><c- f>button</c-><c- p>></c->
    <c- p>&lt;/</c-><c- f>div</c-><c- p>></c->
<c- p>&lt;/</c-><c- f>body</c-><c- p>></c->
</code></pre>
<pre><code class="highlight"><c- kr>const</c-> focusableAreas <c- o>=</c-> document<c- p>.</c->body<c- p>.</c->focusableAreas<c- p>({</c->mode<c- o>:</c-> <c- t>'visible'</c-><c- p>});</c->
focusableAreas <c- o>&amp;&amp;</c-> focusableAreas<c- p>.</c->forEach<c- p>(</c->focusable <c- p>=></c-> <c- p>{</c->
  focusable<c- p>.</c->style<c- p>.</c->outline <c- o>=</c-> <c- t>'5px solid red'</c-><c- p>;</c->
<c- p>});</c->
</code></pre>
     <p>The figure below is the result of this code.</p>
     <figure>
       <img alt="An image about focusableAreas()" src="images/focusableareas-visible-example.png" style="width: 450px;"> 
      <figcaption>Find all visible focusable areas inside the document.</figcaption>
     </figure>
    </div>
    <div class="algorithm" data-algorithm="spatialNavigationSearch steps">
     <dl>
      <dt data-md><dfn class="idl-code" data-dfn-for="Element" data-dfn-type="method" data-export data-lt="spatialNavigationSearch(options)" id="dom-element-spatialnavigationsearch-options"><code>spatialNavigationSearch(<var>dir</var>, <var>options</var>)</code><a class="self-link" href="#dom-element-spatialnavigationsearch-options"></a></dfn>
      <dd data-md>
       <ol>
        <li data-md>
         <p>Let <var>direction</var> be the value of <var>dir</var>.</p>
        <li data-md>
         <p>Let <var>container</var> be</p>
         <ul>
          <li data-md>
           <p>if the value of <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationsearchoptions-container" id="ref-for-dom-spatialnavigationsearchoptions-container">container</a></code> attribute of <var>options</var> is not null,</p>
           <ul>
            <li data-md>
             <p>itself, if it is <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers①③">spatial navigation container</a>.</p>
            <li data-md>
             <p>its nearest <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers①④">spatial navigation container</a> ancestor, otherwise.</p>
           </ul>
          <li data-md>
           <p>else the element’s nearest <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers①⑤">spatial navigation container</a> ancestor.</p>
         </ul>
        <li data-md>
         <p>Let <var>areas</var> be</p>
         <ul>
          <li data-md>
           <p>the value of <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationsearchoptions-candidates" id="ref-for-dom-spatialnavigationsearchoptions-candidates">candidates</a></code> attribute of <var>options</var> if it is not <code>null</code>,</p>
          <li data-md>
           <p>result of <a data-link-type="dfn" href="#find-focusable-areas" id="ref-for-find-focusable-areas①">finding focusable areas</a> within <var>container</var> otherwise.</p>
         </ul>
        <li data-md>
         <p>Return the result of <a data-link-type="dfn" href="#select-the-best-candidate" id="ref-for-select-the-best-candidate">selecting the best candidate</a> among <var>areas</var> within <var>container</var> in <var>direction</var> from the element.</p>
       </ol>
     </dl>
     <p class="note" role="note"><span>Note:</span> When neither a container nor a list of candidates is provided,
this only searches through the visible focusable areas of the nearest <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers①⑥">spatial navigation container</a> ancestor. <em>If there isn’t any, this does not climb further up the ancestry chain,
and the result will be <code>null</code>.</em></p>
    </div>
   </div>
   <div class="api">
    <h2 class="heading settled" data-level="6" id="events-navigationevent"><span class="secno">6. </span><span class="content"> Navigation Events</span><a class="self-link" href="#events-navigationevent"></a></h2>
    <h3 class="heading settled" data-level="6.1" id="interface-focusevent"><span class="secno">6.1. </span><span class="content"> Interface NavigationEvent</span><a class="self-link" href="#interface-focusevent"></a></h3>
    <p>The <code class="idl"><a data-link-type="idl" href="#navigationevent" id="ref-for-navigationevent①">NavigationEvent</a></code> interface provides specific contextual information associated with spatial navigation.</p>
    <p>To create an instance of the <code class="idl"><a data-link-type="idl" href="#navigationevent" id="ref-for-navigationevent②">NavigationEvent</a></code> interface, use the <code class="idl"><a data-link-type="idl" href="#navigationevent" id="ref-for-navigationevent③">NavigationEvent</a></code> constructor,
passing an optional <code class="idl"><a data-link-type="idl" href="#dictdef-navigationeventinit" id="ref-for-dictdef-navigationeventinit">NavigationEventInit</a></code> dictionary.</p>
<pre class="idl highlight def">[<a class="idl-code" data-link-type="extended-attribute" href="https://heycam.github.io/webidl/#Exposed" id="ref-for-Exposed"><c- g>Exposed</c-></a>=<c- n>Window</c->]
<c- b>interface</c-> <dfn class="dfn-paneled idl-code" data-dfn-type="interface" data-export id="navigationevent"><code><c- g>NavigationEvent</c-></code></dfn> : <a class="n" data-link-type="idl-name" href="https://www.w3.org/TR/uievents/#uievent" id="ref-for-uievent①"><c- n>UIEvent</c-></a> {
    <dfn class="idl-code" data-dfn-for="NavigationEvent" data-dfn-type="constructor" data-export data-lt="NavigationEvent(type, eventInitDict)|constructor(type, eventInitDict)|NavigationEvent(type)|constructor(type)" id="dom-navigationevent-navigationevent"><code><c- g>constructor</c-></code><a class="self-link" href="#dom-navigationevent-navigationevent"></a></dfn>(<a class="idl-code" data-link-type="interface" href="https://heycam.github.io/webidl/#idl-DOMString" id="ref-for-idl-DOMString"><c- b>DOMString</c-></a> <dfn class="idl-code" data-dfn-for="NavigationEvent/NavigationEvent(type, eventInitDict), NavigationEvent/constructor(type, eventInitDict), NavigationEvent/NavigationEvent(type), NavigationEvent/constructor(type)" data-dfn-type="argument" data-export id="dom-navigationevent-navigationevent-type-eventinitdict-type"><code><c- g>type</c-></code><a class="self-link" href="#dom-navigationevent-navigationevent-type-eventinitdict-type"></a></dfn>,
                <c- b>optional</c-> <a class="n" data-link-type="idl-name" href="#dictdef-navigationeventinit" id="ref-for-dictdef-navigationeventinit①"><c- n>NavigationEventInit</c-></a> <dfn class="idl-code" data-dfn-for="NavigationEvent/NavigationEvent(type, eventInitDict), NavigationEvent/constructor(type, eventInitDict), NavigationEvent/NavigationEvent(type), NavigationEvent/constructor(type)" data-dfn-type="argument" data-export id="dom-navigationevent-navigationevent-type-eventinitdict-eventinitdict"><code><c- g>eventInitDict</c-></code><a class="self-link" href="#dom-navigationevent-navigationevent-type-eventinitdict-eventinitdict"></a></dfn>);
    <c- b>readonly</c-> <c- b>attribute</c-> <a class="n" data-link-type="idl-name" href="#enumdef-spatialnavigationdirection" id="ref-for-enumdef-spatialnavigationdirection②"><c- n>SpatialNavigationDirection</c-></a> <dfn class="dfn-paneled idl-code" data-dfn-for="NavigationEvent" data-dfn-type="attribute" data-export data-readonly data-type="SpatialNavigationDirection" id="dom-navigationevent-dir"><code><c- g>dir</c-></code></dfn>;
    <c- b>readonly</c-> <c- b>attribute</c-> <a class="n" data-link-type="idl-name" href="https://dom.spec.whatwg.org/#eventtarget" id="ref-for-eventtarget"><c- n>EventTarget</c-></a>? <dfn class="dfn-paneled idl-code" data-dfn-for="NavigationEvent" data-dfn-type="attribute" data-export data-readonly data-type="EventTarget?" id="dom-navigationevent-relatedtarget"><code><c- g>relatedTarget</c-></code></dfn>;
};

<c- b>dictionary</c-> <dfn class="dfn-paneled idl-code" data-dfn-type="dictionary" data-export id="dictdef-navigationeventinit"><code><c- g>NavigationEventInit</c-></code></dfn> : <a class="n" data-link-type="idl-name" href="https://www.w3.org/TR/uievents/#dictdef-uieventinit" id="ref-for-dictdef-uieventinit"><c- n>UIEventInit</c-></a> {
    <a class="n" data-link-type="idl-name" href="#enumdef-spatialnavigationdirection" id="ref-for-enumdef-spatialnavigationdirection③"><c- n>SpatialNavigationDirection</c-></a> <dfn class="idl-code" data-dfn-for="NavigationEventInit" data-dfn-type="dict-member" data-export data-type="SpatialNavigationDirection " id="dom-navigationeventinit-dir"><code><c- g>dir</c-></code><a class="self-link" href="#dom-navigationeventinit-dir"></a></dfn>;
    <a class="n" data-link-type="idl-name" href="https://dom.spec.whatwg.org/#eventtarget" id="ref-for-eventtarget①"><c- n>EventTarget</c-></a>? <dfn class="idl-code" data-default="null" data-dfn-for="NavigationEventInit" data-dfn-type="dict-member" data-export data-type="EventTarget? " id="dom-navigationeventinit-relatedtarget"><code><c- g>relatedTarget</c-></code><a class="self-link" href="#dom-navigationeventinit-relatedtarget"></a></dfn> = <c- b>null</c->;
};
</pre>
    <div class="verbose">
     <h3 class="non-normative heading settled" data-level="6.2" id="events-nav-type"><span class="secno">6.2. </span><span class="content"> Navigation Event Types</span><a class="self-link" href="#events-nav-type"></a></h3>
     <p><em>This section and its subsections are not normative.</em></p>
     <p>The Navigation event types are summarized below.
For full normative details, see <a href="#processing-model">§ 8 Processing Model</a>.</p>
     <h4 class="non-normative heading settled" data-level="6.2.1" id="event-type-navbeforefocus"><span class="secno">6.2.1. </span><span class="content"> <dfn class="dfn-paneled idl-code" data-dfn-for="NavigationEvent" data-dfn-type="event" data-export id="eventdef-navigationevent-navbeforefocus"><code>navbeforefocus</code></dfn></span><a class="self-link" href="#event-type-navbeforefocus"></a></h4>
     <p>This event occurs when there is a valid result of <a data-link-type="dfn" href="#select-the-best-candidate" id="ref-for-select-the-best-candidate①">selecting the best candidate</a>.</p>
     <table class="def">
      <tbody>
       <tr>
        <th>Type 
        <td><strong><code>navbeforefocus</code></strong> 
       <tr>
        <th>Interface 
        <td><code class="idl"><a data-link-type="idl" href="#navigationevent" id="ref-for-navigationevent④">NavigationEvent</a></code> 
       <tr>
        <th>Bubbles 
        <td>Yes 
       <tr>
        <th>Cancelable 
        <td>Yes 
       <tr>
        <th>Attributes of the event 
        <td>
         <dl>
          <dt><code class="idl"><a data-link-type="idl" href="https://dom.spec.whatwg.org/#event" id="ref-for-event">Event</a></code>.<code class="idl"><a data-link-type="idl" href="https://dom.spec.whatwg.org/#dom-event-target" id="ref-for-dom-event-target">target</a></code> 
          <dd>The focused element or if no element focused,
                then <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/dom.html#the-body-element-2" id="ref-for-the-body-element-2">the body element</a> if available, otherwise the root element 
          <dt><code class="idl"><a data-link-type="idl" href="#navigationevent" id="ref-for-navigationevent⑤">NavigationEvent</a></code>.<code class="idl"><a data-link-type="idl" href="#dom-navigationevent-relatedtarget" id="ref-for-dom-navigationevent-relatedtarget">relatedTarget</a></code> 
          <dd>The DOM anchor of the focusable area that will be focused 
          <dt><code class="idl"><a data-link-type="idl" href="#navigationevent" id="ref-for-navigationevent⑥">NavigationEvent</a></code>.<code class="idl"><a data-link-type="idl" href="#dom-navigationevent-dir" id="ref-for-dom-navigationevent-dir">dir</a></code> 
          <dd>The direction of the navigation as requested by the user 
         </dl>
     </table>
     <p>The User Agent <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="dispatches navbeforefocus event | dispatching navbeforefocus event" data-noexport id="dispatches-navbeforefocus-event">dispatches <a class="idl-code" data-link-type="event" href="#eventdef-navigationevent-navbeforefocus" id="ref-for-eventdef-navigationevent-navbeforefocus">navbeforefocus</a> event</dfn> before spatial navigation moves the focus.
The <a data-link-type="dfn" href="https://w3c.github.io/uievents/#event-target" id="ref-for-event-target">event target</a> is the element which has focus and
the <code class="idl"><a data-link-type="idl" href="#dom-navigationevent-relatedtarget" id="ref-for-dom-navigationevent-relatedtarget①">relatedTarget</a></code> is the element which is about to receive focus.</p>
     <p>If <a data-link-type="dfn" href="#navigation-override" id="ref-for-navigation-override">navigation-override</a> is disabled in the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-node-document" id="ref-for-concept-node-document">node document</a> of <var>eventTarget</var> for
the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/origin.html#concept-origin" id="ref-for-concept-origin">origin</a> of the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/browsers.html#active-document" id="ref-for-active-document">active document</a> of the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context" id="ref-for-top-level-browsing-context">top-level browsing context</a>, this event won’t be dispatched.</p>
     <div class="example" id="example-feaa7715">
      <a class="self-link" href="#example-feaa7715"></a> This example shows the <span spec-section="#event-order"></span> when pressing the <code class="key">ArrowRight</code> key.
    For the sake of keeping the description simple,
    this example assumes a User Agent where spatial navigation is triggered using arrow keys. 
      <table class="complex data">
       <thead>
        <tr>
         <th>
         <th>Event type 
         <th><code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/uievents/#keyboardevent" id="ref-for-keyboardevent">KeyboardEvent</a></code>.<code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/uievents/#dom-keyboardevent-key" id="ref-for-dom-keyboardevent-key">key</a></code> 
         <th>Notes 
       <tbody>
        <tr>
         <td>1 
         <td>keydown 
         <td><code class="key">ArrowRight</code> 
         <td>MUST be a key which can activate spatial navigation,
                    such as the arrow keys, or spatial navigation is not activated. 
        <tr>
         <td>2 
         <td>navbeforefocus 
         <td>
         <td>Sent if the candidates for spatial navigation is not <code>null</code>,
                    or this is not generated. 
        <tr>
         <td>3 
         <td>focusin 
         <td>
         <td>Sent before the target element receives focus. 
        <tr>
         <td>4 
         <td>focus 
         <td>
         <td>Sent after the target element receives focus. 
      </table>
     </div>
     <div class="example" id="delegation">
      <a class="self-link" href="#delegation"></a> The following code changes the behavior of spatial navigation
    so that when a scroll container would get focused,
    if it has at least one visible focusable descendant,
    the focus is automatically transferred to it,
    recursively. 
<pre><code class="highlight">document<c- p>.</c->addEventListener<c- p>(</c-><c- t>'navbeforefocus'</c-><c- p>,</c-> e <c- p>=></c-> <c- p>{</c->
    e<c- p>.</c->preventDefault<c- p>();</c->

    <c- a>let</c-> nextTarget <c- o>=</c-> e<c- p>.</c->relatedTarget<c- p>;</c->
    <c- k>if</c-> <c- p>(</c->isSpatialNavigationContainer<c- p>(</c->nextTarget<c- p>))</c-> <c- p>{</c->
        <c- kr>const</c-> areas <c- o>=</c-> nextTarget<c- p>.</c->focusableAreas<c- p>();</c->

        <c- k>if</c-> <c- p>(</c->areas<c- p>.</c->length <c- o>></c-> <c- mi>0</c-><c- p>)</c-> <c- p>{</c->
            nextTarget <c- o>=</c-> nextTarget<c- p>.</c->spatialNavigationSearch<c- p>(</c->e<c- p>.</c->dir<c- p>,</c-> <c- p>{</c-> candidates<c- o>:</c-> areas <c- p>});</c->
        <c- p>}</c->
    <c- p>}</c->
    nextTarget<c- p>.</c->focus<c- p>();</c->
<c- p>});</c->

<c- a>function</c-> isSpatialNavigationContainer<c- p>(</c->element<c- p>)</c-> <c- p>{</c->
    <c- k>return</c-> <c- p>(</c-><c- o>!</c->element<c- p>.</c->parentElement<c- p>)</c-> <c- o>||</c->
        <c- p>(</c->element<c- p>.</c->nodeName <c- o>===</c-> <c- t>'IFRAME'</c-><c- p>)</c-> <c- o>||</c->
        <c- p>(</c->isScrollContainer<c- p>(</c->element<c- p>))</c-> <c- o>||</c->
        <c- p>(</c->isCSSSpatNavContain<c- p>(</c->element<c- p>));</c->
<c- p>}</c->
</code></pre>
     </div>
     <h4 class="non-normative heading settled" data-level="6.2.2" id="event-type-navnotarget"><span class="secno">6.2.2. </span><span class="content"> <dfn class="dfn-paneled idl-code" data-dfn-for="NavigationEvent" data-dfn-type="event" data-export id="eventdef-navigationevent-navnotarget"><code>navnotarget</code></dfn></span><a class="self-link" href="#event-type-navnotarget"></a></h4>
     <p>This event occurs before going up the tree to search candidates in the
nearest ancestor <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers①⑦">spatial navigation container</a> when spatial navigation has failed to find any candidate
within the current <span id="ref-for-spatial-navigation-containers①⑧">spatial navigation container</span>,
and in cases where the <span id="ref-for-spatial-navigation-containers①⑨">spatial navigation container</span> is scrollable,
when it cannot be scrolled further.</p>
     <table class="def">
      <tbody>
       <tr>
        <th>Type 
        <td><strong><code>navnotarget</code></strong> 
       <tr>
        <th>Interface 
        <td><code class="idl"><a data-link-type="idl" href="#navigationevent" id="ref-for-navigationevent⑦">NavigationEvent</a></code> 
       <tr>
        <th>Bubbles 
        <td>Yes 
       <tr>
        <th>Cancelable 
        <td>Yes 
       <tr>
        <th>Attributes of the event 
        <td>
         <dl>
          <dt><code class="idl"><a data-link-type="idl" href="https://dom.spec.whatwg.org/#event" id="ref-for-event①">Event</a></code>.<code class="idl"><a data-link-type="idl" href="https://dom.spec.whatwg.org/#dom-event-target" id="ref-for-dom-event-target①">target</a></code> 
          <dd>The focused element or if no element focused,
                then <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/dom.html#the-body-element-2" id="ref-for-the-body-element-2①">the body element</a> if available, otherwise the root element 
          <dt><code class="idl"><a data-link-type="idl" href="#navigationevent" id="ref-for-navigationevent⑧">NavigationEvent</a></code>.<code class="idl"><a data-link-type="idl" href="#dom-navigationevent-relatedtarget" id="ref-for-dom-navigationevent-relatedtarget②">relatedTarget</a></code> 
          <dd>The <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers②⓪">spatial navigation container</a> that was searched in. 
          <dt><code class="idl"><a data-link-type="idl" href="#navigationevent" id="ref-for-navigationevent⑨">NavigationEvent</a></code>.<code class="idl"><a data-link-type="idl" href="#dom-navigationevent-dir" id="ref-for-dom-navigationevent-dir①">dir</a></code> 
          <dd>The direction of the navigation as requested by the user 
         </dl>
     </table>
     <p>The User Agent <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="dispatches navnotarget event | dispatching navnotarget event" data-noexport id="dispatches-navnotarget-event">dispatches <a class="idl-code" data-link-type="event" href="#eventdef-navigationevent-navnotarget" id="ref-for-eventdef-navigationevent-navnotarget">navnotarget</a> event</dfn> with initializing the <a data-link-type="dfn" href="https://w3c.github.io/uievents/#event-target" id="ref-for-event-target①">event target</a> as the element which has focus and
the <code class="idl"><a data-link-type="idl" href="#dom-navigationevent-relatedtarget" id="ref-for-dom-navigationevent-relatedtarget③">relatedTarget</a></code> as <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers②①">spatial navigation container</a> of the <span id="ref-for-event-target②">event target</span>.</p>
     <p>If <a data-link-type="dfn" href="#navigation-override" id="ref-for-navigation-override①">navigation-override</a> is disabled in the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-node-document" id="ref-for-concept-node-document①">node document</a> of <var>eventTarget</var> for
the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/origin.html#concept-origin" id="ref-for-concept-origin①">origin</a> of the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/browsers.html#active-document" id="ref-for-active-document①">active document</a> of the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context" id="ref-for-top-level-browsing-context①">top-level browsing context</a>, this event won’t be dispatched.</p>
     <div class="example" id="example-e7e46248">
      <a class="self-link" href="#example-e7e46248"></a> This example shows the <span spec-section="#event-order"></span> when pressing the <code class="key">ArrowDown</code> key in the situation like the following figure.
    For the sake of keeping the description simple,
    this example assumes a User Agent where spatial navigation is triggered using arrow keys. 
      <figure>
        <img alt="An image about navnotarget" src="images/navnotarget-example-1.png" style="width: 200px;"> 
       <figcaption>Moving focus when there isn’t any candidate in the <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container">scroll container</a>.</figcaption>
      </figure>
      <table class="complex data">
       <thead>
        <tr>
         <th>
         <th>Event type 
         <th>Event target 
         <th><code>relatedTarget</code> 
         <th>Notes 
       <tbody>
        <tr>
         <td>1 
         <td>keydown 
         <td><code>#box2</code> 
         <td>N/A 
         <td>MUST be a key which can activate spatial navigation,
                    such as the arrow keys,
                    otherwise spatial navigation is not triggered. 
        <tr>
         <td>2 
         <td>navnotarget 
         <td><code>#box2</code> 
         <td><code>#scrollContainer</code> 
         <td>Sent if <code>#scrollContainer</code> doesn’t contain any candidate and
                cannot be scrolled,
                otherwise this would not be generated. 
        <tr>
         <td>3 
         <td>navbeforefocus 
         <td><code>#box2</code> 
         <td><code>#box3</code> 
         <td>Sent if the candidates in <code>#container</code> is not <code>null</code>,
                otherwise this would not be fired. 
        <tr>
         <td>4 
         <td>focusin 
         <td><code>#box3</code> 
         <td><code>#box2</code> 
         <td>Sent before the target element receives focus. 
        <tr>
         <td>5 
         <td>focus 
         <td><code>#box3</code> 
         <td><code>#box2</code> 
         <td>Sent after the target element receives focus. 
      </table>
      <p>The result of this example is the figure as follows:</p>
      <figure>
        <img alt="An image of the result about navnotarget" src="images/navnotarget-example-2.png" style="width: 200px;"> 
       <figcaption>The result of moving focus when there isn’t any candidate in the <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scrollport" id="ref-for-scrollport④">scrollport</a> and <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container①">scroll container</a> cannot be scrolled.</figcaption>
      </figure>
      <p>This example uses the markup as follows:</p>
<pre class="lang-css highlight"><c- f>#container </c-><c- p>{</c->
    <c- k>width</c-><c- p>:</c-> <c- m>900</c-><c- l>px</c-><c- p>;</c->
    <c- k>height</c-><c- p>:</c-> <c- m>1400</c-><c- l>px</c-><c- p>;</c->
<c- p>}</c->

<c- f>#scrollContainer </c-><c- p>{</c->
    <c- k>width</c-><c- p>:</c-> <c- m>700</c-><c- l>px</c-><c- p>;</c->
    <c- k>height</c-><c- p>:</c-> <c- m>700</c-><c- l>px</c-><c- p>;</c->
    <c- k>overflow-x</c-><c- p>:</c-> hidden<c- p>;</c->
    <c- k>overflow-y</c-><c- p>:</c-> auto<c- p>;</c->
<c- p>}</c->

<c- f>.item </c-><c- p>{</c->
    <c- k>width</c-><c- p>:</c-> <c- m>150</c-><c- l>px</c-><c- p>;</c->
    <c- k>height</c-><c- p>:</c-> <c- m>110</c-><c- l>px</c-><c- p>;</c->
    <c- k>background-color</c-><c- p>:</c-> blue<c- p>;</c->
<c- p>}</c->

<c- f>.item:focus </c-><c- p>{</c->
    <c- k>background-color</c-><c- p>:</c-> red<c- p>;</c->
<c- p>}</c->
</pre>
<pre class="lang-html highlight"><c- p>&lt;</c-><c- f>div</c-> <c- e>id</c-><c- o>=</c-><c- s>"container"</c-><c- p>></c->
    <c- p>&lt;</c-><c- f>div</c-> <c- e>id</c-><c- o>=</c-><c- s>"scrollContainer"</c-><c- p>></c->
        <c- p>&lt;</c-><c- f>div</c-> <c- e>id</c-><c- o>=</c-><c- s>"box1"</c-> <c- e>class</c-><c- o>=</c-><c- s>"item"</c-> <c- e>tabindex</c-><c- o>=</c-><c- s>"0"</c-><c- p>></c->Box 1<c- p>&lt;/</c-><c- f>div</c-><c- p>></c->
        <c- p>&lt;</c-><c- f>div</c-> <c- e>id</c-><c- o>=</c-><c- s>"box2"</c-> <c- e>class</c-><c- o>=</c-><c- s>"item"</c-> <c- e>tabindex</c-><c- o>=</c-><c- s>"0"</c-><c- p>></c->Box 2<c- p>&lt;/</c-><c- f>div</c-><c- p>></c->
    <c- p>&lt;/</c-><c- f>div</c-><c- p>></c->
    <c- p>&lt;</c-><c- f>div</c-> <c- e>id</c-><c- o>=</c-><c- s>"box3"</c-> <c- e>class</c-><c- o>=</c-><c- s>"item"</c-> <c- e>tabindex</c-><c- o>=</c-><c- s>"0"</c-><c- p>></c->Box 3<c- p>&lt;/</c-><c- f>div</c-><c- p>></c->
<c- p>&lt;/</c-><c- f>div</c-><c- p>></c->
</pre>
     </div>
     <div class="example" id="loop">
      <a class="self-link" href="#loop"></a> The following code changes the behavior of spatial navigation
    to trap the focus within a <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers②②">spatial navigation container</a> which is vertically scrollable.
    When no further focusable elements can be found in the requested direction
    and the <span id="ref-for-spatial-navigation-containers②③">spatial navigation container</span> cannot be scrolled any further,
    the focus loops back to the other side instead of moving outside of it. 
      <p>However, the focus can still be moved outside by sequential navigation,
    mouse interaction,
    or programmatic calls to <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/interaction.html#dom-focus" id="ref-for-dom-focus①">focus()</a></code>.</p>
<pre><code class="highlight">scrollContainer<c- p>.</c->addEventListener<c- p>(</c-><c- t>'navnotarget'</c-><c- p>,</c-> e <c- p>=></c-> <c- p>{</c->
    <c- a>let</c-> nextTarget <c- o>=</c-> <c- kc>null</c-><c- p>;</c->
    <c- kr>const</c-> verticalDir <c- o>=</c-> <c- p>[</c-><c- t>'up'</c-><c- p>,</c-> <c- t>'down'</c-><c- p>];</c->
    <c- kr>const</c-> candidates <c- o>=</c-> e<c- p>.</c->relatedTarget<c- p>.</c->focusableAreas<c- p>({</c-><c- t>'mode'</c-><c- o>:</c-> <c- t>'all'</c-><c- p>});</c->

    <c- c1>// Prevent default only when navigation direction is on y-axis</c->
    <c- k>if</c-> <c- p>(</c->verticalDir<c- p>.</c->includes<c- p>(</c->e<c- p>.</c->dir<c- p>)</c-> <c- o>&amp;&amp;</c-> <c- p>(</c->candidates<c- p>.</c->length <c- o>></c-> <c- mi>0</c-><c- p>))</c-> <c- p>{</c->
        e<c- p>.</c->preventDefault<c- p>();</c->

        <c- k>if</c-> <c- p>(</c->e<c- p>.</c->dir <c- o>===</c-> <c- t>'down'</c-><c- p>)</c-> <c- p>{</c->
            nextTarget <c- o>=</c-> candidates<c- p>[</c-><c- mi>0</c-><c- p>];</c->
        <c- p>}</c-> <c- k>else</c-> <c- k>if</c-> <c- p>(</c->e<c- p>.</c->dir <c- o>===</c-> <c- t>'up'</c-><c- p>)</c-> <c- p>{</c->
            nextTarget <c- o>=</c-> candidates<c- p>[</c->candidates<c- p>.</c->length<c- o>-</c-><c- mi>1</c-><c- p>];</c->
        <c- p>}</c->
        nextTarget<c- p>.</c->focus<c- p>();</c->
    <c- p>}</c->
<c- p>});</c->
</code></pre>
     </div>
    </div>
   </div>
   <h2 class="heading settled" data-level="7" id="policy-feature"><span class="secno">7. </span><span class="content"> The <a data-link-type="dfn" href="#navigation-override" id="ref-for-navigation-override②">navigation-override</a> <a data-link-type="dfn" href="https://w3c.github.io/webappsec-feature-policy/#policy-controlled-feature" id="ref-for-policy-controlled-feature">policy-controlled feature</a></span><a class="self-link" href="#policy-feature"></a></h2>
   <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="navigation-override">navigation-override</dfn> <a data-link-type="dfn" href="https://w3c.github.io/webappsec-feature-policy/#policy-controlled-feature" id="ref-for-policy-controlled-feature①">policy-controlled feature</a> controls
	the availability of mechanisms that enables the page author
	to take control over the behavior of spatial navigation,
	or to cancel it outright.</p>
   <ul>
    <li data-md>
     <p>The feature name is "<code>navigation-override</code>"</p>
    <li data-md>
     <p>The <a data-link-type="dfn" href="https://w3c.github.io/webappsec-feature-policy/#default-allowlist" id="ref-for-default-allowlist">default allowlist</a> for <a data-link-type="dfn" href="#navigation-override" id="ref-for-navigation-override③">navigation-override</a> is "<code>self</code>"</p>
   </ul>
   <p>As defined in further details in <a href="#nav">§ 8.3 Navigation</a>,
	if <a data-link-type="dfn" href="#navigation-override" id="ref-for-navigation-override④">navigation-override</a> is disabled in a document,
	the navigation events (see <a href="#events-navigationevent">§ 6 Navigation Events</a>) will not be fired.</p>
   <p class="note" role="note"><span>Note:</span> This is to prevent a hostile iframe from using these events
	in order to highjack the focus.
	We recognize that there exist other mechanisms predating spatial navigation
	that malicious the author could use
	to interfere with the user’s ability to control where the focus goes.
	Despite that, it seems worthwhile to attempt not to increase this attack surface,
	although it is possible that such attacks are already sufficiently easy to perform
	that this is a lost cause.
	Further feedback on this topic,
	based on experience with implementation or with mitigating such attacks,
	is very welcome.</p>
   <h2 class="heading settled" data-level="8" id="processing-model"><span class="secno">8. </span><span class="content"> Processing Model</span><a class="self-link" href="#processing-model"></a></h2>
   <div class="verbose">
     The <a href="#overview">§ 3 Overview</a> section gives a high level idea of how spatial navigation works,
to help readers of this specification build a general mental model.
It uses intuitive but imprecise terminology,
and glosses over many details
for the sake of readability. 
    <p>This section defines the corresponding normative behavior
and aims for as much detail as necessary
to fully define the behavior.</p>
   </div>
   <h3 class="heading settled" data-level="8.1" id="glossary"><span class="secno">8.1. </span><span class="content"> Glossary</span><a class="self-link" href="#glossary"></a></h3>
   <p>The following term definitions have been specified to explain the processing model for spatial navigation.
See the links within the definitions for more information.</p>
   <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="boundary-box">boundary box</dfn> of an object is defined as follows:</p>
   <ul>
    <li data-md>
     <p>if the object is a point, the boundary box is that point</p>
    <li data-md>
     <p>if the object is a <a data-link-type="dfn" href="https://drafts.csswg.org/css-display-3/#box" id="ref-for-box">box</a> or <a data-link-type="dfn" href="https://drafts.csswg.org/css-break-4/#box-fragment" id="ref-for-box-fragment">box fragment</a>, the boundary box is the <a data-link-type="dfn" href="https://drafts.csswg.org/css2/box.html#x14" id="ref-for-x14">border box</a> of that box or fragment</p>
    <li data-md>
     <p>if the object is a <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/interaction.html#focusable-area" id="ref-for-focusable-area">focusable area</a> which is not an element, the boundary box is the axis-aligned the bounding box of that <span id="ref-for-focusable-area①">focusable area</span></p>
   </ul>
   <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="inside-area">inside area</dfn> of an object is defined as follows:</p>
   <ul>
    <li data-md>
     <p>if the object is a <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container②">scroll container</a>, its <a data-link-type="dfn" href="https://drafts.csswg.org/css-scroll-snap-1/#optimal-viewing-region" id="ref-for-optimal-viewing-region">optimal viewing region</a></p>
    <li data-md>
     <p>if the object is a <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-document" id="ref-for-concept-document①">document</a>, the viewport of its <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/browsers.html#browsing-context" id="ref-for-browsing-context">browsing context</a></p>
    <li data-md>
     <p>if the object is a <a data-link-type="dfn" href="https://drafts.csswg.org/css-display-3/#box" id="ref-for-box①">box</a> or <a data-link-type="dfn" href="https://drafts.csswg.org/css-break-4/#box-fragment" id="ref-for-box-fragment①">box fragment</a>, its <a data-link-type="dfn" href="#boundary-box" id="ref-for-boundary-box">boundary box</a></p>
    <li data-md>
     <p>otherwise, the <a data-link-type="dfn" href="https://drafts.csswg.org/css-scroll-snap-1/#optimal-viewing-region" id="ref-for-optimal-viewing-region①">optimal viewing region</a> of its nearest ancestor <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container③">scroll container</a></p>
   </ul>
   <p class="note" role="note"><span>NOTE:</span> If an object is offscreen, the <a data-link-type="dfn" href="#inside-area" id="ref-for-inside-area">inside area</a> should be the nearest visible ancestor container.</p>
   <p class="issue" id="issue-c7f6d991"><a class="self-link" href="#issue-c7f6d991"></a> CSS should have a term for “border box taking into account corner shaping properties like border-radius”. <a href="https://github.com/w3c/csswg-drafts/issues/2324">&lt;https://github.com/w3c/csswg-drafts/issues/2324></a></p>
   <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="search-origin">search origin</dfn> is the origin for searching next target.</p>
   <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="spatial-navigation-starting-point">spatial navigation starting point</dfn> is the origin for searching next target which is set by the User Agent. It is initially unset and it can be element or point.</p>
   <p class="note" role="note"><span>Note:</span> For example, the User Agent could set it to the position of the user’s click if the user clicks on the document contents,
and unset when the focus is moved (by spatial navigation or any other means).</p>
   <p>If the User Agent sets both a <a data-link-type="dfn" href="#spatial-navigation-starting-point" id="ref-for-spatial-navigation-starting-point">spatial navigation starting point</a> and a <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/interaction.html#sequential-focus-navigation-starting-point" id="ref-for-sequential-focus-navigation-starting-point">sequential focus navigation starting point</a>,
they must not be set differently.</p>
   <h3 class="heading settled" data-level="8.2" id="grouping"><span class="secno">8.2. </span><span class="content"> Groupings of elements</span><a class="self-link" href="#grouping"></a></h3>
   <p>While the processing model for spatial navigation
is to work from the layout of the document
and the relative position of focusable elements,
the User Agent is required to prioritize finding elements
from a local logical grouping,
only looking for focusable elements outside of the grouping
if a suitable one cannot be found inside it (see <a href="#nav">§ 8.3 Navigation</a> for details).</p>
   <p>Such groupings are called <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="spatial-navigation-containers">spatial navigation containers</dfn>.</p>
   <p><span class="cssapi">By default, </span><a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers②④">spatial navigation containers</a> are established by:</p>
   <ul>
    <li data-md>
     <p>The viewport of a <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/browsers.html#browsing-context" id="ref-for-browsing-context①">browsing context</a> (not limited to the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context" id="ref-for-top-level-browsing-context②">top-level browsing context</a>)</p>
    <li data-md>
     <p><a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container④">scroll containers</a></p>
   </ul>
   <div class="cssapi"> Additional <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers②⑤">spatial navigation containers</a> can be created using the <a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-contain" id="ref-for-propdef-spatial-navigation-contain②">spatial-navigation-contain</a> property (see <a href="#container">§ 9.1 Creating additional spatial navigation containers: the spatial-navigation-contain property</a>). </div>
   <h3 class="heading settled" data-level="8.3" id="nav"><span class="secno">8.3. </span><span class="content"> Navigation</span><a class="self-link" href="#nav"></a></h3>
   <p>The processing model for spatial navigation describes how spatial navigation works in general.</p>
   <figure class="verbose non-normative">
    <object data="images/spatnav_processing_model_diagram.svg" type="image/svg+xml"></object>
    <figcaption> Overview of the Spatial navigation processing model <br> This figure is not normative.
        It gives an overview of the processing model further defined in this section,
        assuming that the <a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-action" id="ref-for-propdef-spatial-navigation-action①">spatial-navigation-action</a> property has its initial value of <a class="css" data-link-type="maybe" href="#valdef-spatial-navigation-action-auto" id="ref-for-valdef-spatial-navigation-action-auto">auto</a>. </figcaption>
   </figure>
   <div class="algorithm" data-algorithm="to run the spatial navigation steps">
    <p>To run the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="spatial-navigation-steps">spatial navigation steps</dfn> in <var>direction</var>, do the following:</p>
    <ol>
     <li data-md>
      <p>Let <var>searchOrigin</var> be the result of <a data-link-type="dfn" href="#set-the-search-origin" id="ref-for-set-the-search-origin">setting the search origin</a>.</p>
     <li data-md>
      <ul>
       <li data-md>
        <p>If <var>searchOrigin</var> is an <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#boundary-point-node" id="ref-for-boundary-point-node">node</a>,
let <var>eventTarget</var> be <var>searchOrigin</var></p>
       <li data-md>
        <p>else (<a data-link-type="dfn" href="https://infra.spec.whatwg.org/#assert" id="ref-for-assert">assert</a>: <var>searchOrigin</var> is a position)
let <var>eventTarget</var> be the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#boundary-point-node" id="ref-for-boundary-point-node①">node</a> which contains <var>searchOrigin</var></p>
      </ul>
     <li data-md>
      <p>If <var>eventTarget</var> is the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-document" id="ref-for-concept-document②">Document</a> or the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#document-element" id="ref-for-document-element">document element</a>,
    set <var>eventTarget</var> be <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/dom.html#the-body-element-2" id="ref-for-the-body-element-2②">the body element</a> if it is not <code>null</code> or to the <span id="ref-for-document-element①">document element</span> otherwise.</p>
     <li data-md>
      <ul>
       <li class="cssapi">If <var>eventTarget</var> is <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container⑤">scroll container</a> and the computed value of the <a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-action" id="ref-for-propdef-spatial-navigation-action②">spatial-navigation-action</a> property on <var>eventTarget</var> is <a class="css" data-link-type="maybe" href="#valdef-spatial-navigation-action-scroll" id="ref-for-valdef-spatial-navigation-action-scroll">scroll</a> and <var>eventTarget</var> <a data-link-type="dfn" href="#can-be-manually-scrolled" id="ref-for-can-be-manually-scrolled">can be manually scrolled</a>,
        then <a data-link-type="dfn" href="#directionally-scroll-an-element" id="ref-for-directionally-scroll-an-element">directionally scroll the element</a> <var>eventTarget</var> and return.
       <li>
        <span class="cssapi">Else,</span> if <var>eventTarget</var> is either a <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container⑥">scroll container</a> or the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-document" id="ref-for-concept-document③">document</a> 
        <ol>
         <li data-md>
          <p>Let <var>candidates</var> be the result of <a data-link-type="dfn" href="#find-focusable-areas" id="ref-for-find-focusable-areas②">finding focusable areas</a> within <var>eventTarget</var> with the argument <var>visibleOnly</var> set to <code>false</code> <span class="cssapi">if computed value of the <a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-action" id="ref-for-propdef-spatial-navigation-action③">spatial-navigation-action</a> property on <var>eventTarget</var> is <a class="css" data-link-type="maybe" href="#valdef-spatial-navigation-action-focus" id="ref-for-valdef-spatial-navigation-action-focus">focus</a> or to <code>true</code> otherwise. </span></p>
         <li data-md>
          <ul>
           <li class="cssapi">If
        the computed value of the <a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-action" id="ref-for-propdef-spatial-navigation-action④">spatial-navigation-action</a> property on <var>eventTarget</var> is not <a class="css" data-link-type="maybe" href="#valdef-spatial-navigation-action-focus" id="ref-for-valdef-spatial-navigation-action-focus①">focus</a> and <var>eventTarget</var> <a data-link-type="dfn" href="#can-be-manually-scrolled" id="ref-for-can-be-manually-scrolled①">can be manually scrolled</a>,
        then <a data-link-type="dfn" href="#directionally-scroll-an-element" id="ref-for-directionally-scroll-an-element①">directionally scroll the element</a> <var>eventTarget</var> in <var>direction</var> and return.
           <li>
            <span class="cssapi">Else </span>if <var>candidates</var> contains at least 1 item: 
            <ol>
             <li data-md>
              <p>Let <var>bestCandidate</var> be the result of <a data-link-type="dfn" href="#select-the-best-candidate" id="ref-for-select-the-best-candidate②">selecting the best candidate</a> within <var>candidates</var> in <var>direction</var> starting from <var>searchOrigin</var></p>
             <li data-md>
              <p><a data-link-type="dfn" href="#dispatches-navbeforefocus-event" id="ref-for-dispatches-navbeforefocus-event">Dispatches navbeforefocus event</a> at <var>eventTarget</var> with <var>direction</var> and <var>bestCandidate</var>.</p>
             <li data-md>
              <p>Run the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/interaction.html#focusing-steps" id="ref-for-focusing-steps">focusing steps</a> for <var>bestCandidate</var> and return</p>
            </ol>
           <li>Else, fall back to the next step.
          </ul>
        </ol>
       <li>Else, fall back to the next step.
      </ul>
     <li data-md>
      <p>Let <var>container</var> be the nearest ancestor of <var>eventTarget</var> that is a <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers②⑥">spatial navigation container</a>.</p>
     <li data-md>
      <p><i>Loop</i>: Let <var>candidates</var> be the result of <a data-link-type="dfn" href="#find-focusable-areas" id="ref-for-find-focusable-areas③">finding focusable areas</a> within <var>container</var> with the argument <var>visibleOnly</var> set to <code>false</code> <span class="cssapi"> if computed value of the <a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-action" id="ref-for-propdef-spatial-navigation-action⑤">spatial-navigation-action</a> property on <var>container</var> is <a class="css" data-link-type="maybe" href="#valdef-spatial-navigation-action-focus" id="ref-for-valdef-spatial-navigation-action-focus②">focus</a> or to <code>true</code> otherwise,
excluding <var>eventTarget</var> </span></p>
     <li data-md>
      <p>If <var>candidates</var> is empty:</p>
     <li class="cssapi">If the computed value of the <a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-action" id="ref-for-propdef-spatial-navigation-action⑥">spatial-navigation-action</a> property on <var>container</var> is not <a class="css" data-link-type="maybe" href="#valdef-spatial-navigation-action-focus" id="ref-for-valdef-spatial-navigation-action-focus③">focus</a> and <var>container</var> is a <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container⑦">scroll container</a> that <a data-link-type="dfn" href="#can-be-manually-scrolled" id="ref-for-can-be-manually-scrolled②">can be manually scrolled</a>, <a data-link-type="dfn" href="#directionally-scroll-an-element" id="ref-for-directionally-scroll-an-element②">directionally scroll the element</a> <var>container</var> in <var>direction</var> and return. 
     <li class="cssapi">Else,
     <ol>
      <li data-md>
       <p><a data-link-type="dfn" href="#dispatches-navnotarget-event" id="ref-for-dispatches-navnotarget-event">Dispatches navnotarget event</a> at <var>eventTarget</var> with <var>direction</var> and <var>container</var>.</p>
      <li data-md>
       <ul>
        <li data-md>
         <p>If <var>container</var> is the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#document-element" id="ref-for-document-element②">document element</a> of the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context" id="ref-for-top-level-browsing-context③">top-level browsing context</a>,
then return.
The User Agent may transfer focus to its own controls (if any) honouring <var>direction</var>.</p>
        <li data-md>
         <p>Else, if <var>container</var> is the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#document-element" id="ref-for-document-element③">document element</a> of a <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/browsers.html#nested-browsing-context" id="ref-for-nested-browsing-context">nested browsing context</a> then:</p>
         <ol>
          <li data-md>
           <p>Set <var>searchOrigin</var> to <var>container</var>’s <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-container" id="ref-for-browsing-context-container">browsing context container</a></p>
          <li data-md>
           <p>Set <var>eventTarget</var> be <var>searchOrigin</var></p>
          <li data-md>
           <p>Set <var>container</var> to the nearest ancestor of <var>eventTarget</var> that is a <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers②⑦">spatial navigation container</a>.</p>
          <li data-md>
           <p>Return to the step labeled <i>loop</i>.</p>
         </ol>
        <li data-md>
         <p>Else, set <var>container</var> to its closest ancestor that is itself a <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers②⑧">spatial navigation container</a> and return to the step labeled <i>loop</i>.</p>
       </ul>
     </ol>
     <li data-md>
      <p>Let <var>bestCandidate</var> be the result of <a data-link-type="dfn" href="#select-the-best-candidate" id="ref-for-select-the-best-candidate③">selecting the best candidate</a> within <var>candidates</var> in <var>direction</var> starting from <var>eventTarget</var>.</p>
     <li data-md>
      <p><a data-link-type="dfn" href="#dispatches-navbeforefocus-event" id="ref-for-dispatches-navbeforefocus-event①">Dispatches navbeforefocus event</a> at <var>eventTarget</var> with <var>direction</var> and <var>bestCandidate</var>.</p>
     <li data-md>
      <p>Run the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/interaction.html#focusing-steps" id="ref-for-focusing-steps①">focusing steps</a> for <var>bestCandidate</var> and return.</p>
    </ol>
   </div>
   <h3 class="heading settled" data-level="8.4" id="heuristics"><span class="secno">8.4. </span><span class="content"> Focus Navigation Heuristics</span><a class="self-link" href="#heuristics"></a></h3>
   <p class="note" role="note"><span>Note:</span> The following algorithms are inspired from Chrome’s implementation
as well as from the <a href="https://www.w3.org/TR/WICD/#focus-handling">old WICD Spec</a>.
Implementors who find better approaches or refinements to these approaches are strongly
encouraged to provide feedback and help improve this specification
in order to maximize interoperability.
In particular, divergences in how User Agents <a data-link-type="dfn" href="#find-focusable-areas" id="ref-for-find-focusable-areas④">find focusable areas</a> may cause some elements to be focusable in some User Agents but not in others,
which would be bad for users.</p>
   <p>All geometrical operations in this section are defined to work on the result of CSS layout,
including all graphical transformations, such as <a data-link-type="dfn" href="https://drafts.csswg.org/css-position-3/#relative-position" id="ref-for-relative-position">relative positioning</a> or <a data-link-type="biblio" href="#biblio-css-transforms-1">[CSS-TRANSFORMS-1]</a>.</p>
   <div class="algorithm" data-algorithm="to set the search origin">
    <p>To <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="set the search origin | setting the search origin" data-noexport id="set-the-search-origin">set the <a data-link-type="dfn" href="#search-origin" id="ref-for-search-origin">search origin</a></dfn>,
run the following steps:</p>
    <ol>
     <li data-md>
      <p>Let <var>searchOrigin</var> be the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/interaction.html#dom-anchor" id="ref-for-dom-anchor">DOM anchor</a> of the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/interaction.html#currently-focused-area-of-a-top-level-browsing-context" id="ref-for-currently-focused-area-of-a-top-level-browsing-context">currently focused area of a top-level browsing context</a>.</p>
     <li data-md>
      <p>If the <a data-link-type="dfn" href="#spatial-navigation-starting-point" id="ref-for-spatial-navigation-starting-point①">spatial navigation starting point</a> is not <code>null</code> and it is inside <var>searchOrigin</var>,
then return it.</p>
     <li data-md>
      <p>Otherwise, return <var>searchOrigin</var>.</p>
    </ol>
    <p>If the status of <var>focus target</var> changed not by moving the focus, <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="update the search origin | updating the search origin" data-noexport id="update-the-search-origin">update the <a data-link-type="dfn" href="#search-origin" id="ref-for-search-origin①">search origin</a></dfn> as following:</p>
    <ol>
     <li data-md>
      <p>If <var>focus target</var> becomes <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/semantics-other.html#concept-element-disabled" id="ref-for-concept-element-disabled">actually disabled</a> or <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/interaction.html#expressly-inert" id="ref-for-expressly-inert">expressly inert</a> or
not <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/rendering.html#being-rendered" id="ref-for-being-rendered">being rendered</a>,
then let <var>searchOrigin</var> be the <a data-link-type="dfn" href="#boundary-box" id="ref-for-boundary-box①">boundary box</a> of <var>focus target</var>.</p>
     <li data-md>
      <p>If <var>focus target</var> is <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#nodes-are-removed" id="ref-for-nodes-are-removed">removed</a>,
then let <var>searchOrigin</var> be the <a data-link-type="dfn" href="#boundary-box" id="ref-for-boundary-box②">boundary box</a> of <var>focus target</var> with the position of <var>focus target</var> when it existed.</p>
     <li data-md>
      <p>If <var>focus target</var> is completely off-screen,
then let <var>searchOrigin</var> be the viewport of <var>focus target</var>’s nearest visible <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers②⑨">spatial navigation container</a>.</p>
    </ol>
    <p class="note" role="note"><span>NOTE:</span> The User Agent should <a data-link-type="dfn" href="#update-the-search-origin" id="ref-for-update-the-search-origin">update the search origin</a>, for example,
when the focused element was scrolled out by mouse scrolling or vanished from the viewport.</p>
   </div>
   <div class="algorithm" data-algorithm="to find focusable areas">
    <p>To <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="find focusable areas | finding focusable areas" data-noexport id="find-focusable-areas">find focusable areas</dfn> within a containing element <var>C</var>,
with an optional <var>visibleOnly</var> argument that defaults to <code>true</code>,
run the following steps:</p>
    <ol>
     <li data-md>
      <p>Let <var>focusables</var> be the <a data-link-type="dfn" href="https://infra.spec.whatwg.org/#ordered-set" id="ref-for-ordered-set">set</a> of all the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/interaction.html#focusable-area" id="ref-for-focusable-area②">focusable areas</a> whose <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/interaction.html#dom-anchor" id="ref-for-dom-anchor①">DOM anchor</a> are descendants of <var>C</var>.
In the case of <a data-link-type="dfn" href="https://drafts.csswg.org/css-display-3/#box" id="ref-for-box②">boxes</a> with several <a data-link-type="dfn" href="https://drafts.csswg.org/css-break-4/#box-fragment" id="ref-for-box-fragment②">box fragments</a>, each <span id="ref-for-box-fragment③">box fragment</span> is considered separately.</p>
     <li data-md>
      <p>The User Agent should <a data-link-type="dfn" href="https://infra.spec.whatwg.org/#list-remove" id="ref-for-list-remove">remove</a> from <var>focusables</var> items that have a <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/interaction.html#dom-anchor" id="ref-for-dom-anchor②">DOM anchor</a> whose <a data-link-type="element-attr" href="https://html.spec.whatwg.org/multipage/interaction.html#attr-tabindex" id="ref-for-attr-tabindex"><code>tabindex</code></a> attribute is set to a negative value.</p>
      <p class="note" role="note"><span>Note:</span> This is a "SHOULD" in order to mirror the exclusion of elements with negative tabindex
from the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/interaction.html#sequential-focus-navigation-order" id="ref-for-sequential-focus-navigation-order">sequential focus navigation order</a> as defined in <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/interaction.html#attr-tabindex" id="ref-for-attr-tabindex①">tabindex</a>.</p>
     <li data-md>
      <p>If <var>visibleOnly</var> is <code>false</code>,
return <var>focusables</var>.</p>
      <p class="note" role="note"><span>Note:</span> <var>focusables</var> may be empty</p>
     <li data-md>
      <p>Let <var>visibles</var> be the subset of items in <var>focusables</var> whose <a data-link-type="dfn" href="#boundary-box" id="ref-for-boundary-box③">boundary box</a> is at least partly within the <a data-link-type="dfn" href="#inside-area" id="ref-for-inside-area①">inside area</a> of <var>C</var>.</p>
      <div class="advisement non-normative"> Except for elements that are in the currently non visible part of a scroller,
spatial navigation does not automatically exclude
elements which cannot be clicked on,
for example, due to being obscured by some other element.
To avoid breaking assumptions in
the application logic if a user actually focuses and activates such an element,
and to avoid confusing users by focusing invisible or apparently unreachable elements,
the author should use make these elements unreachable to spatial navigation
using the same best practices as for making elements unreachable to sequential navigation,
such as using <code>tab-index="-1"</code> or the <a href="https://github.com/WICG/inert"><code>inert</code></a> attribute. </div>
     <li data-md>
      <p>Return <var>visibles</var>.</p>
      <p class="note" role="note"><span>Note:</span> <var>visibles</var> may be empty</p>
    </ol>
   </div>
   <div class="algorithm" data-algorithm="to select the best candidate">
    <p>To <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="select the best candidate | selecting the best candidate" data-noexport id="select-the-best-candidate">select the best candidate</dfn> within a <a data-link-type="dfn" href="https://infra.spec.whatwg.org/#ordered-set" id="ref-for-ordered-set①">set</a> of <var>candidates</var> in a direction <var>dir</var>,
starting from <var>searchOrigin</var>,
run the following steps:</p>
    <ol>
     <li data-md>
      <p>If <var>candidates</var> is <a data-link-type="dfn" href="https://infra.spec.whatwg.org/#list-empty" id="ref-for-list-empty">empty</a>, return <code>null</code></p>
     <li data-md>
      <p>If <var>candidates</var> contains a single item, return that item</p>
     <li data-md>
      <p>Let <var>insiders</var> be the subset of <var>candidates</var></p>
      <ul>
       <li data-md>
        <p>whose boundary box fully overlaps with <a data-link-type="dfn" href="#inside-area" id="ref-for-inside-area②">inside area</a> of <var>searchOrigin</var></p>
       <li data-md>
        <p>whose boundary box partially overlaps with <a data-link-type="dfn" href="#inside-area" id="ref-for-inside-area③">inside area</a> of <var>searchOrigin</var> as</p>
        <ul>
         <li data-md>
          <p>top edge is below the top edge of <var>searchOrigin</var>’s <a data-link-type="dfn" href="#boundary-box" id="ref-for-boundary-box④">boundary box</a> if <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-down" id="ref-for-dom-spatialnavigationdirection-down">down</a></code></p>
         <li data-md>
          <p>bottom edge is above the bottom edge of <var>searchOrigin</var>’s <a data-link-type="dfn" href="#boundary-box" id="ref-for-boundary-box⑤">boundary box</a> if <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-up" id="ref-for-dom-spatialnavigationdirection-up">up</a></code></p>
         <li data-md>
          <p>right edge is left of the right edge of <var>searchOrigin</var>’s <a data-link-type="dfn" href="#boundary-box" id="ref-for-boundary-box⑥">boundary box</a> if <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-left" id="ref-for-dom-spatialnavigationdirection-left">left</a></code></p>
         <li data-md>
          <p>left edge is right of the left edge of <var>searchOrigin</var>’s <a data-link-type="dfn" href="#boundary-box" id="ref-for-boundary-box⑦">boundary box</a> if <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-right" id="ref-for-dom-spatialnavigationdirection-right">right</a></code></p>
        </ul>
        <p class="note" role="note"><span>NOTE:</span> More detail condition about how the element is overlapped with the search origin affects the sequence of focus movement.
The sequence of focus movement is related to UX, so it depends on the UA-defined mechanism.</p>
      </ul>
      <p class="note" role="note"><span>Note:</span> this sub-setting is necessary to avoid going in the opposite direction than the one requested.</p>
     <li data-md>
      <ul>
       <li data-md>
        <p>If <var>insiders</var> is non empty,</p>
        <ol>
         <li data-md>
          <p>Let <var>closest subset</var> be the subset of <var>insiders</var> whose <a data-link-type="dfn" href="#boundary-box" id="ref-for-boundary-box⑧">boundary box</a>’s</p>
          <ul>
           <li data-md>
            <p>top edge is closest to the top edge of <a data-link-type="dfn" href="#inside-area" id="ref-for-inside-area④">inside area</a> of <var>searchOrigin</var> if <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-down" id="ref-for-dom-spatialnavigationdirection-down①">down</a></code></p>
           <li data-md>
            <p>bottom edge is closest to the bottom edge of <a data-link-type="dfn" href="#inside-area" id="ref-for-inside-area⑤">inside area</a> of <var>searchOrigin</var> if <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-up" id="ref-for-dom-spatialnavigationdirection-up①">up</a></code></p>
           <li data-md>
            <p>right edge is closest to the right edge of <a data-link-type="dfn" href="#inside-area" id="ref-for-inside-area⑥">inside area</a> of <var>searchOrigin</var> if <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-left" id="ref-for-dom-spatialnavigationdirection-left①">left</a></code></p>
           <li data-md>
            <p>left edge is closest to the left edge of <a data-link-type="dfn" href="#inside-area" id="ref-for-inside-area⑦">inside area</a> of <var>searchOrigin</var> if <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-right" id="ref-for-dom-spatialnavigationdirection-right①">right</a></code></p>
          </ul>
         <li data-md>
          <p>If <var>closest subset</var> contains a single item,
return that item,
else return the first item of <var>closest subset</var> in document order,
unless its <a data-link-type="dfn" href="#boundary-box" id="ref-for-boundary-box⑨">boundary box</a> overlaps with the <span id="ref-for-boundary-box①⓪">boundary box</span> of another item
and that item is higher in the CSS <a data-link-type="dfn" href="https://drafts.csswg.org/css2/zindex.html#painting-order" id="ref-for-painting-order">painting order</a>.
In that case, return that item instead,
unless it too is overlapped with another higher item, recursively.</p>
        </ol>
       <li data-md>
        <p>Else</p>
        <ol>
         <li data-md>
          <p>Set <var>candidates</var> be the subset of its items which satisfies one of the following conditions:</p>
          <ul>
           <li data-md>
            <p>the item doesn’t overlap with <var>searchOrigin</var> and its <a data-link-type="dfn" href="#boundary-box" id="ref-for-boundary-box①①">boundary box</a>’s</p>
            <ul>
             <li data-md>
              <p>top edge is below the bottom edge of <var>searchOrigin</var>’s <a data-link-type="dfn" href="#boundary-box" id="ref-for-boundary-box①②">boundary box</a> if <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-down" id="ref-for-dom-spatialnavigationdirection-down②">down</a></code></p>
             <li data-md>
              <p>bottom edge is above the top edge of <var>searchOrigin</var>’s <a data-link-type="dfn" href="#boundary-box" id="ref-for-boundary-box①③">boundary box</a> if <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-up" id="ref-for-dom-spatialnavigationdirection-up②">up</a></code></p>
             <li data-md>
              <p>right edge is left of the left edge of <var>searchOrigin</var>’s <a data-link-type="dfn" href="#boundary-box" id="ref-for-boundary-box①④">boundary box</a> if <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-left" id="ref-for-dom-spatialnavigationdirection-left②">left</a></code></p>
             <li data-md>
              <p>left edge is right of the right edge of <var>searchOrigin</var>’s <a data-link-type="dfn" href="#boundary-box" id="ref-for-boundary-box①⑤">boundary box</a> if <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-right" id="ref-for-dom-spatialnavigationdirection-right②">right</a></code></p>
            </ul>
          </ul>
         <li data-md>
          <p>For each <var>candidate</var> in <var>candidates</var>, <a data-link-type="dfn" href="#find-the-shortest-distance" id="ref-for-find-the-shortest-distance">find the shortest distance</a> between <var>searchOrigin</var>.</p>
         <li data-md>
          <p>Return the item of the <var>candidates</var> set that has the smallest distance.
If several have the same distance,
return the first one in document order,
unless its <a data-link-type="dfn" href="#boundary-box" id="ref-for-boundary-box①⑥">boundary box</a> overlaps with the <span id="ref-for-boundary-box①⑦">boundary box</span> of another item at the same distance,
and that item is higher in the CSS <a data-link-type="dfn" href="https://drafts.csswg.org/css2/zindex.html#painting-order" id="ref-for-painting-order①">painting order</a>.
In that case, return that item instead,
unless it too is overlapped with another higher item at the same distance, recursively.</p>
        </ol>
      </ul>
    </ol>
   </div>
   <div class="algorithm" data-algorithm="to find the shortest the distance">
     To <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="find the shortest distance | finding the shortest distance" data-noexport id="find-the-shortest-distance">find the shortest distance</dfn> between a <var>reference</var> and a <var>candidate</var> in direction <var>dir</var>,
find the points <var>P1</var> and <var>P2</var>,
respectively within the boundary boxes of the <var>reference</var> and of the <var>candidate</var>,
that minimize the <var>distance</var> as defined as below: 
<pre class="prod"><var>distance</var> = <var>euclidean</var> <a data-link-type="grammar" href="https://drafts.csswg.org/css-values-4/#mult-one-plus" id="ref-for-mult-one-plus">+</a> <var>displacement</var> - <var>alignment</var> - <var>sqrt(Overlap)</var>
</pre>
    <p>The meaning of each term is as follows:</p>
    <dl>
     <dt><var>euclidean</var> 
     <dd> The euclidean distance between <var>P1</var> and <var>P2</var> 
     <dt><var>displacement</var> 
     <dd>
       The degree of displacement in <var>dir</var> between the <var>reference</var> and the <var>candidate</var>,
        defined as 
<pre><code><var>displacement</var> = (absolute distance on the axis orthogonal to <var>dir</var> between <var>P1</var> and <var>P2</var> +
                <var>orthogonalBias</var>) *
               <var>orthogonalWeight</var>
</code></pre>
     <dt><var>orthogonalBias</var>: 
     <dd>
      <ul>
       <li data-md>
        <p>If the <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-left" id="ref-for-dom-spatialnavigationdirection-left③">left</a></code> or <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-right" id="ref-for-dom-spatialnavigationdirection-right③">right</a></code>,
the height of the axis-aligned bounding box of <var>reference</var> / 2</p>
       <li data-md>
        <p>Else if the <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-up" id="ref-for-dom-spatialnavigationdirection-up③">up</a></code> or <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-down" id="ref-for-dom-spatialnavigationdirection-down③">down</a></code>,
the width of the axis-aligned bounding box of <var>reference</var> / 2</p>
      </ul>
     <dt><var>orthogonalWeight</var>: 
     <dd>
      <ul>
       <li data-md>
        <p>If the <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-left" id="ref-for-dom-spatialnavigationdirection-left④">left</a></code> or <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-right" id="ref-for-dom-spatialnavigationdirection-right④">right</a></code>, 30</p>
       <li data-md>
        <p>Else if the <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-up" id="ref-for-dom-spatialnavigationdirection-up④">up</a></code> or <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-down" id="ref-for-dom-spatialnavigationdirection-down④">down</a></code>, 2</p>
      </ul>
     <dt><var>alignment</var> 
     <dd>
       The degree of alignment in <var>dir</var> between the <var>reference</var> and the <var>candidate</var>,
        defined as: 
<pre><code><var>alignment</var> = <var>alignBias</var> * <var>alignWeight</var>
</code></pre>
     <dt><var>alignBias</var>: 
     <dd>
      <ul>
       <li data-md>
        <p>If the <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-left" id="ref-for-dom-spatialnavigationdirection-left⑤">left</a></code> or <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-right" id="ref-for-dom-spatialnavigationdirection-right⑤">right</a></code>, <var>projectedOverlap</var> / height of the axis-aligned bounding box of <var>reference</var></p>
       <li data-md>
        <p>Else if the <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-up" id="ref-for-dom-spatialnavigationdirection-up⑤">up</a></code> or <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-down" id="ref-for-dom-spatialnavigationdirection-down⑤">down</a></code>, <var>projectedOverlap</var> / width of the axis-aligned bounding box of <var>reference</var></p>
      </ul>
     <dt><var>projectedOverlap</var>: 
     <dd>
      <ul>
       <li data-md>
        <p>If the <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-left" id="ref-for-dom-spatialnavigationdirection-left⑥">left</a></code> or <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-right" id="ref-for-dom-spatialnavigationdirection-right⑥">right</a></code>,
the length of the overlap between the horizontal projections onto the vertical axis
of the <var>reference</var> and the <var>candidate</var></p>
       <li data-md>
        <p>Else if the <var>dir</var> is <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-up" id="ref-for-dom-spatialnavigationdirection-up⑥">up</a></code> or <code class="idl"><a data-link-type="idl" href="#dom-spatialnavigationdirection-down" id="ref-for-dom-spatialnavigationdirection-down⑥">down</a></code>,
the length of the overlap between the vertical projections onto the horizontal axis
of the <var>reference</var> and the <var>candidate</var></p>
      </ul>
      <figure>
        <img alt src="images/projected_overlap.png" style="width: 500px;"> 
       <figcaption>projectedOverlap</figcaption>
      </figure>
     <dt><var>alignWeight</var>: 
     <dd>5 
     <dt><var>sqrt(Overlap)</var> 
     <dd> The square root of area of overlap between the <var>reference</var> and the <var>candidate</var>,
        or 0 if they do not overlap. 
    </dl>
    <p class="note" role="note"><span>Note:</span> This general formula was picked from several plausible alternatives,
based on which one most often matches intuition
when used to select the best candidate
in a series of <a href="https://wicg.github.io/spatial-navigation/tests/ux/list.html">UX test cases</a>.
Similarly, the values of <var>alignWeight</var> and <var>orthogonalWeight</var> were also determined experimentally based on the same test cases.
The resulting formula is somewhat complicated,
but seems to give good answers.
Suggestions for improvements or simplifications are welcome.</p>
   </div>
   <div class="cssapi">
    <h2 class="heading settled" data-level="9" id="declarative"><span class="secno">9. </span><span class="content"> Controlling spatial navigation through declarative means</span><a class="self-link" href="#declarative"></a></h2>
    <h3 class="heading settled" data-level="9.1" id="container"><span class="secno">9.1. </span><span class="content"> Creating additional spatial navigation containers: the <a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-contain" id="ref-for-propdef-spatial-navigation-contain③">spatial-navigation-contain</a> property</span><a class="self-link" href="#container"></a></h3>
    <table class="def propdef" data-link-for-hint="spatial-navigation-contain">
     <tbody>
      <tr>
       <th>Name:
       <td><dfn class="dfn-paneled css" data-dfn-type="property" data-export id="propdef-spatial-navigation-contain">spatial-navigation-contain</dfn>
      <tr class="value">
       <th><a href="https://drafts.csswg.org/css-values/#value-defs">Value:</a>
       <td class="prod">auto <a data-link-type="grammar" href="https://drafts.csswg.org/css-values-4/#comb-one" id="ref-for-comb-one">|</a> contain
      <tr>
       <th><a href="https://drafts.csswg.org/css-cascade/#initial-values">Initial:</a>
       <td>auto
      <tr>
       <th>Applies to:
       <td><a href="https://drafts.csswg.org/css-pseudo/#generated-content" title="Includes ::before and ::after pseudo-elements.">all elements</a>
      <tr>
       <th><a href="https://drafts.csswg.org/css-cascade/#inherited-property">Inherited:</a>
       <td>no
      <tr>
       <th><a href="https://drafts.csswg.org/css-values/#percentages">Percentages:</a>
       <td>n/a
      <tr>
       <th><a href="https://drafts.csswg.org/css-cascade/#computed">Computed value:</a>
       <td>as specified
      <tr>
       <th>Canonical order:
       <td>per grammar
      <tr>
       <th><a href="https://drafts.csswg.org/web-animations/#animation-type">Animation type:</a>
       <td>discrete
    </table>
    <dl>
     <dt><dfn class="css" data-dfn-for="spatial-navigation-contain" data-dfn-type="value" data-export id="valdef-spatial-navigation-contain-auto">auto<a class="self-link" href="#valdef-spatial-navigation-contain-auto"></a></dfn> 
     <dd>If the element is a <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container⑧">scroll container</a> then it establishes a <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers③⓪">spatial navigation container</a>,
        otherwise it does not. 
     <dt><dfn class="css" data-dfn-for="spatial-navigation-contain" data-dfn-type="value" data-export id="valdef-spatial-navigation-contain-contain">contain<a class="self-link" href="#valdef-spatial-navigation-contain-contain"></a></dfn> 
     <dd>The element establishes a <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers③①">spatial navigation container</a> 
    </dl>
    <p class="note" role="note"><span>Note:</span> In addition, as per <a href="#grouping">§ 8.2 Groupings of elements</a>, the viewport of a <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/browsers.html#browsing-context" id="ref-for-browsing-context②">browsing context</a> (not limited to the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context" id="ref-for-top-level-browsing-context④">top-level browsing context</a>)
        also establishes a <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers③②">spatial navigation container</a>.</p>
    <div class="example" id="example-6752923a">
     <a class="self-link" href="#example-6752923a"></a> The following example shows a simplified TV program schedule or calendar.
    It has a grid of elements representing TV shows or calendar entries
    and some UI buttons around it. 
     <p>In this case, the grid is quite sparse,
    so if the user tries to move down from "Foo",
    focus would be moved to "Next Week",
    as it is objectively closer in the down direction.
    The same is true for going down from "Bar":
    the focus would move to "Previous Week".</p>
     <div class="output">
      <div id="example-cal">
       <button>Previous Week</button>
       <table>
        <tbody>
         <tr>
          <td>
          <th>M
          <th>T
          <th>W
          <th>T
          <th>F
          <th>S
          <th>S 
         <tr>
          <td>0-6
          <td>
          <td>
          <td>
          <td>
          <td>
          <td>
          <td><a href="#">Foo</a> 
         <tr>
          <td>6-9
          <td><a href="#">Bar</a>
          <td>
          <td>
          <td>
          <td>
          <td>
          <td>
         <tr>
          <td>9-12
          <td>
          <td><a href="#">Bat</a>
          <td>
          <td>
          <td>
          <td>
          <td>
         <tr>
          <td>12-18
          <td>
          <td>
          <td>
          <td>
          <td>
          <td>
          <td>
         <tr>
          <td>18-21
          <td>
          <td>
          <td>
          <td>
          <td>
          <td>
          <td><a href="#">Woo</a> 
         <tr>
          <td>21-24
          <td>
          <td>
          <td>
          <td>
          <td>
          <td><a href="#">Baz</a>
          <td>
       </table>
       <button>Next Week</button>
      </div>
     </div>
<pre><code class="highlight"><c- p>&lt;</c-><c- f>div</c-><c- p>></c->
    <c- p>&lt;</c-><c- f>button</c-><c- p>></c->Previous Week<c- p>&lt;/</c-><c- f>button</c-><c- p>></c->
    <c- p>&lt;</c-><c- f>table</c-><c- p>></c->
        <c- p>&lt;</c-><c- f>tr</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>th</c-><c- p>></c->M<c- p>&lt;</c-><c- f>th</c-><c- p>></c->T<c- p>&lt;</c-><c- f>th</c-><c- p>></c->W<c- p>&lt;</c-><c- f>th</c-><c- p>></c->T<c- p>&lt;</c-><c- f>th</c-><c- p>></c->F<c- p>&lt;</c-><c- f>th</c-><c- p>></c->S<c- p>&lt;</c-><c- f>th</c-><c- p>></c->S
        <c- p>&lt;</c-><c- f>tr</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>></c->0-6<c- p>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>a</c-> <c- e>href</c-><c- o>=</c-><c- s>"#"</c-><c- p>></c->Foo<c- p>&lt;/</c-><c- f>a</c-><c- p>></c->
        <c- p>&lt;</c-><c- f>tr</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>></c->6-9<c- p>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>a</c-> <c- e>href</c-><c- o>=</c-><c- s>"#"</c-><c- p>></c->Bar<c- p>&lt;/</c-><c- f>a</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>></c->
        <c- p>&lt;</c-><c- f>tr</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>></c->9-12<c- p>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>a</c-> <c- e>href</c-><c- o>=</c-><c- s>"#"</c-><c- p>></c->Bat<c- p>&lt;/</c-><c- f>a</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>></c->
        <c- p>&lt;</c-><c- f>tr</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>></c->12-18<c- p>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>></c->
        <c- p>&lt;</c-><c- f>tr</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>></c->18-21<c- p>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>a</c-> <c- e>href</c-><c- o>=</c-><c- s>"#"</c-><c- p>></c->Woo<c- p>&lt;/</c-><c- f>a</c-><c- p>></c->
        <c- p>&lt;</c-><c- f>tr</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>></c->21-24<c- p>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>>&lt;</c-><c- f>a</c-> <c- e>href</c-><c- o>=</c-><c- s>"#"</c-><c- p>></c->Baz<c- p>&lt;/</c-><c- f>a</c-><c- p>>&lt;</c-><c- f>td</c-><c- p>></c->
    <c- p>&lt;/</c-><c- f>table</c-><c- p>></c->
    <c- p>&lt;</c-><c- f>button</c-><c- p>></c->Next Week<c- p>&lt;/</c-><c- f>button</c-><c- p>></c->
<c- p>&lt;/</c-><c- f>div</c-><c- p>></c->
</code></pre>
     <p>However, the author may want to provide a different navigation experience
    giving priority to movements inside the grid once you have focused one of its items
    because the elements in the table are semantically related to each other.</p>
     <p>Adding <code class="highlight"><c- f>table </c-><c- p>{</c-> <c- k>spatial-navigation-contain</c-><c- p>:</c-> contain<c- p>;</c-> <c- p>}</c-></code> to the stylesheet
    would result this behavior.</p>
     <p>After that, the focus would move down from "Foo" to "Woo" instead of "Next Week",
    and from "Bar" to "Bat" instead of "Previous Week".</p>
     <p>It would still be possible to move the focus out of the table.
    For example, the focus would move to "Next week" by going right from "Foo"
    since there is nothing in the grid that is to the right.</p>
    </div>
    <p class="note" role="note"><span>Note:</span> the <a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-contain" id="ref-for-propdef-spatial-navigation-contain④">spatial-navigation-contain</a> property is <a data-link-type="dfn" href="#at-risk" id="ref-for-at-risk①">at-risk</a>.</p>
   </div>
   <h3 class="heading settled" data-level="9.2" id="css-property-spatialnavigationaction"><span class="secno">9.2. </span><span class="content"> Controlling the interaction with scrolling: the <a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-action" id="ref-for-propdef-spatial-navigation-action⑦">spatial-navigation-action</a> property</span><a class="self-link" href="#css-property-spatialnavigationaction"></a></h3>
   <table class="def propdef" data-link-for-hint="spatial-navigation-action">
    <tbody>
     <tr>
      <th>Name:
      <td><dfn class="dfn-paneled css" data-dfn-type="property" data-export id="propdef-spatial-navigation-action">spatial-navigation-action</dfn>
     <tr class="value">
      <th><a href="https://drafts.csswg.org/css-values/#value-defs">Value:</a>
      <td class="prod">auto <a data-link-type="grammar" href="https://drafts.csswg.org/css-values-4/#comb-one" id="ref-for-comb-one①">|</a> focus <span id="ref-for-comb-one②">|</span> scroll
     <tr>
      <th><a href="https://drafts.csswg.org/css-cascade/#initial-values">Initial:</a>
      <td>auto
     <tr>
      <th>Applies to:
      <td><a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container⑨">scroll containers</a>
     <tr>
      <th><a href="https://drafts.csswg.org/css-cascade/#inherited-property">Inherited:</a>
      <td>no
     <tr>
      <th><a href="https://drafts.csswg.org/css-values/#percentages">Percentages:</a>
      <td>n/a
     <tr>
      <th><a href="https://drafts.csswg.org/css-cascade/#computed">Computed value:</a>
      <td>as specified
     <tr>
      <th>Canonical order:
      <td>per grammar
     <tr>
      <th><a href="https://drafts.csswg.org/web-animations/#animation-type">Animation type:</a>
      <td>discrete
   </table>
   <p>When the focus is inside of a scroll container and the user triggers spatial navigation,
it is somewhat ambiguous whether they are requesting that the focus be moved in that direction,
or whether the document should be scrolled in that direction.
By default, this is automatically determined,
but this property allows the author to decide between focusing or scrolling.</p>
   <p>The precise behavior is defined in <a href="#nav">§ 8.3 Navigation</a>,
but a high level description of the effect of each value is provided below.</p>
   <p>When spatial navigation is triggered,
the behavior depends on the value of the <a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-action" id="ref-for-propdef-spatial-navigation-action⑧">spatial-navigation-action</a> on the currently focused element
if that element is a <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container①⓪">scroll container</a>,
or of its nearest <span id="ref-for-scroll-container①①">scroll container</span> ancestor if it isn’t.</p>
   <dl>
    <dt><dfn class="dfn-paneled css" data-dfn-for="spatial-navigation-action" data-dfn-type="value" data-export id="valdef-spatial-navigation-action-auto">auto</dfn> 
    <dd> If there are visible focusable elements within the <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container①②">scroll container</a> in the direction requested,
        the closest one becomes focused.
        Otherwise, the <span id="ref-for-scroll-container①③">scroll container</span> is scrolled in the direction requested. 
    <dt><dfn class="dfn-paneled css" data-dfn-for="spatial-navigation-action" data-dfn-type="value" data-export id="valdef-spatial-navigation-action-focus">focus</dfn> 
    <dd>
      The focus is moved to the nearest focusable element within the <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container①④">scroll container</a>,
        regardless of whether it is visible.
        If there are none,
        the scroll container is <em>not</em> scrolled,
        and the search continues up the ancestry chain instead. 
     <p class="note" role="note"><span>Note:</span> The <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container①⑤">scroll container</a> may be scrolled as a side effect of focusing
        an element which was previously not in view,
        but it will not <a data-link-type="dfn" href="#directionally-scroll-an-element" id="ref-for-directionally-scroll-an-element③">be directionally scrolled</a>.</p>
     <p class="note" role="note"><span>Note:</span> If the <a class="css" data-link-type="maybe" href="#valdef-spatial-navigation-action-focus" id="ref-for-valdef-spatial-navigation-action-focus④">focus</a> value is given to <a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-action" id="ref-for-propdef-spatial-navigation-action⑨">spatial-navigation-action</a>, <a class="idl-code" data-link-type="event" href="#eventdef-navigationevent-navnotarget" id="ref-for-eventdef-navigationevent-navnotarget①">navnotarget</a> event occurs when there isn’t any visible candidate in the given direction within the viewport of
        the <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers③③">spatial navigation container</a> even if the container can be scrolled more.</p>
    <dt><dfn class="dfn-paneled css" data-dfn-for="spatial-navigation-action" data-dfn-type="value" data-export id="valdef-spatial-navigation-action-scroll">scroll</dfn> 
    <dd>
      If the currently focused element is not itself a <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container①⑥">scroll container</a>,
        this value on an ancestor <span id="ref-for-scroll-container①⑦">scroll container</span> has the same effect as <a class="css" data-link-type="maybe" href="#valdef-spatial-navigation-action-auto" id="ref-for-valdef-spatial-navigation-action-auto①">auto</a>. 
     <p>If the currently focused element is a <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container①⑧">scroll container</a>,
        it is scrolled in the direction requested without changing which element is in focus,
        regardless of the presence of focusable descendants.</p>
     <p class="note" role="note"><span>Note:</span> This means that spatial navigation can be used
        to move the focus to a <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container①⑨">scroll container</a> and to scroll it,
        but not to move the focus to its descendants.
        However, if the focus is moved to a descendant by some other mean
        (such as pressing the <span class="key">Tab</span> key or using the &lt;<code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/interaction.html#dom-focus" id="ref-for-dom-focus②">focus()</a></code>> method)
        spatial navigation can be used to move the focus to other focusable descendants.</p>
     <p class="note" role="note"><span>Note:</span> The <span class="css">scroll</span> value is <a data-link-type="dfn" href="#at-risk" id="ref-for-at-risk②">at-risk</a>.</p>
   </dl>
   <p class="note" role="note"><span>Note:</span> Earlier version of this specification did not offer a declarative way
to opt into the behavior defined by <a class="css" data-link-type="maybe" href="#valdef-spatial-navigation-action-focus" id="ref-for-valdef-spatial-navigation-action-focus⑤">focus</a>,
and instead offered a cancellable event that would be fired before scrolling,
so that the author could implement that behavior themselves.
However, cancellable events related to scrolling can cause performance problems,
so this event was removed and the <a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-action" id="ref-for-propdef-spatial-navigation-action①⓪">spatial-navigation-action</a> property was introduced instead.</p>
   <div class="example" id="example-59a246d8">
    <a class="self-link" href="#example-59a246d8"></a> In this example, a scrollable container is specified with <code class="highlight">spatial-navigation-action: focus</code>.
Inside the container, there is an element which is out of the view within a <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scrollport" id="ref-for-scrollport⑤">scrollport</a>.
Pressing the down arrow key moves the focus directly to it without scrolling manually. 
    <figure>
      <img alt src="images/spatnav-action.png" style="width: 500px;"> 
     <figcaption>Moving focus from "Box 2" to "Box 3" without manually scrolling</figcaption>
    </figure>
<pre><code class="highlight"><c- p>&lt;</c-><c- f>div</c-> <c- e>class</c-><c- o>=</c-><c- s>'scroller'</c-><c- p>></c->
    <c- p>&lt;</c-><c- f>button</c-> <c- e>class</c-><c- o>=</c-><c- s>'item'</c-><c- p>></c->Box 1<c- p>&lt;/</c-><c- f>button</c-><c- p>></c->
    <c- p>&lt;</c-><c- f>button</c-> <c- e>class</c-><c- o>=</c-><c- s>'item'</c-><c- p>></c->Box 2<c- p>&lt;/</c-><c- f>button</c-><c- p>></c->
    <c- p>&lt;</c-><c- f>button</c-> <c- e>class</c-><c- o>=</c-><c- s>'item'</c-><c- p>></c->Box 3<c- p>&lt;/</c-><c- f>button</c-><c- p>></c->
<c- p>&lt;/</c-><c- f>div</c-><c- p>></c->
</code></pre>
<pre><code class="highlight"><c- f>.scroller </c-><c- p>{</c->
    <c- k>display</c-><c- p>:</c-> grid<c- p>;</c->
    <c- k>grid-template-columns</c-><c- p>:</c-> <c- nf>repeat</c-><c- p>(</c-><c- m>1</c-><c- p>,</c-> <c- m>1</c-><c- l>fr</c-><c- p>);</c->
    <c- k>height</c-><c- p>:</c-> <c- m>300</c-><c- l>px</c-><c- p>;</c->
    <c- k>width</c-><c- p>:</c-> <c- m>200</c-><c- l>px</c-><c- p>;</c->
    <c- k>overflow-y</c-><c- p>:</c-> scroll<c- p>;</c->
    <c- k>spatial-navigation-action</c-><c- p>:</c-> focus<c- p>;</c->
<c- p>}</c->
<c- f>.item </c-><c- p>{</c->
    <c- k>height</c-><c- p>:</c-> <c- m>100</c-><c- l>px</c-><c- p>;</c->
    <c- k>width</c-><c- p>:</c-> <c- m>100</c-><c- l>px</c-><c- p>;</c->
    <c- k>margin</c-><c- p>:</c-> <c- m>50</c-><c- l>px</c-> auto<c- p>;</c->
    <c- k>background-color</c-><c- p>:</c-> blue<c- p>;</c->
<c- p>}</c->
<c- f>:focus </c-><c- p>{</c->
    <c- k>background-color</c-><c- p>:</c-> red<c- p>;</c->
<c- p>}</c->
</code></pre>
   </div>
   <h3 class="heading settled" data-level="9.3" id="css-property-spatialnavigationfunction"><span class="secno">9.3. </span><span class="content"> Selecting the navigation algorithm: the <a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-function" id="ref-for-propdef-spatial-navigation-function①">spatial-navigation-function</a> property</span><a class="self-link" href="#css-property-spatialnavigationfunction"></a></h3>
   <table class="def propdef" data-link-for-hint="spatial-navigation-function">
    <tbody>
     <tr>
      <th>Name:
      <td><dfn class="dfn-paneled css" data-dfn-type="property" data-export id="propdef-spatial-navigation-function">spatial-navigation-function</dfn>
     <tr class="value">
      <th><a href="https://drafts.csswg.org/css-values/#value-defs">Value:</a>
      <td class="prod">normal <a data-link-type="grammar" href="https://drafts.csswg.org/css-values-4/#comb-one" id="ref-for-comb-one③">|</a> grid
     <tr>
      <th><a href="https://drafts.csswg.org/css-cascade/#initial-values">Initial:</a>
      <td>normal
     <tr>
      <th>Applies to:
      <td><a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers③④">spatial navigation containers</a>
     <tr>
      <th><a href="https://drafts.csswg.org/css-cascade/#inherited-property">Inherited:</a>
      <td>no
     <tr>
      <th><a href="https://drafts.csswg.org/css-values/#percentages">Percentages:</a>
      <td>n/a
     <tr>
      <th><a href="https://drafts.csswg.org/css-cascade/#computed">Computed value:</a>
      <td>as specified
     <tr>
      <th>Canonical order:
      <td>per grammar
     <tr>
      <th><a href="https://drafts.csswg.org/web-animations/#animation-type">Animation type:</a>
      <td>discrete
   </table>
   <p>The default algorithm of spatial navigation specified in the <a href="#processing-model">§ 8 Processing Model</a> may need the fine tune depending on the layout types.
This property allows the author to indicate which navigation algorithm is reasonable for spatial navigation behavior.</p>
   <p>Its values are defined as follows:</p>
   <dl>
    <dt><dfn class="css" data-dfn-for="spatial-navigation-function" data-dfn-type="value" data-export id="valdef-spatial-navigation-function-normal">normal<a class="self-link" href="#valdef-spatial-navigation-function-normal"></a></dfn> 
    <dd>
      Moves the focus with the default focus navigation algorithm defined by UA. 
     <p>In general, the focus moves to the element with the closest distance calculated by <a data-link-type="dfn" href="#find-the-shortest-distance" id="ref-for-find-the-shortest-distance①">finding the shortest distance</a>.</p>
    <dt><dfn class="css" data-dfn-for="spatial-navigation-function" data-dfn-type="value" data-export id="valdef-spatial-navigation-function-grid">grid<a class="self-link" href="#valdef-spatial-navigation-function-grid"></a></dfn> 
    <dd>
      Moves the focus to the element which is aligned most in the navigation direction. 
     <ul>
      <li data-md>
       <p>If there are more than one aligned candidates in the navigation direction,
 select the element with the closest distance along the axis which corresponds to the navigation direction.
In case of multiple elements with the same distance,
 select the element with the minimum amount of alignment.</p>
      <li data-md>
       <p>Else if there isn’t any aligned candidate in a given direction,
 select the element with the closest distance along the axis which corresponds to the navigation direction.
In case of multiple elements with the same distance,
 select the element with the minimum distance along the axis which is orthogonal to the navigation direction.</p>
     </ul>
   </dl>
   <p class="note" role="note"><span>NOTE:</span> These values are negotiated with the users' preferences which seems natural spatial navigation behavior for their pages.</p>
   <div class="example" id="example-c86d0d36">
    <a class="self-link" href="#example-c86d0d36"></a> This example shows how the focus moves differently by the value of <code class="highlight">spatial-navigation-function</code>. 
    <figure>
      <img alt src="images/spatnav-function.png" style="width: 500px;"> 
     <figcaption>Moving focus from "A" to one of the candidate elements</figcaption>
    </figure>
    <p>Let the element which contains "A", "B" and "C" is the <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers③⑤">spatial navigation container</a>.</p>
    <p>When the user presses the down arrow key,
    if <code class="highlight">normal</code> value is given to <code class="highlight">spatial-navigation-function</code> of the element, the focus will move to "B".
    Otherwise, <code class="highlight">grid</code> value was specified to the element, the focus will move to "C".</p>
   </div>
   <h2 class="no-num heading settled" id="scrolling"><span class="content">Appendix A. Scroll extensions</span><a class="self-link" href="#scrolling"></a></h2>
   <p>This section proposes a few extensions to CSS
that should be integrated in upstream specifications,
but are hosted here until then.</p>
   <div class="algorithm" data-algorithm="can be manually scrolled">
    <p class="issue" id="issue-942e7041"><a class="self-link" href="#issue-942e7041"></a> Terminology like this should be in <a data-link-type="biblio" href="#biblio-cssom-view-1">[CSSOM-VIEW-1]</a>, <a data-link-type="biblio" href="#biblio-css-overflow-3">[CSS-OVERFLOW-3]</a>, <a data-link-type="biblio" href="#biblio-css-scroll-snap-1">[CSS-SCROLL-SNAP-1]</a>. <a href="https://github.com/w3c/csswg-drafts/issues/2322">&lt;https://github.com/w3c/csswg-drafts/issues/2322></a></p>
    <p>An element <var>e</var> <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="can be manually scrolled | can be scrolled manually | cannot be scrolled manually | cannot be manually scrolled" data-noexport id="can-be-manually-scrolled">can be manually scrolled</dfn> in a given direction <var>d</var> if:</p>
    <ul>
     <li data-md>
      <p>The <a data-link-type="dfn" href="https://drafts.csswg.org/css-display-3/#principal-box" id="ref-for-principal-box">principal box</a> established by <var>e</var> is a <a data-link-type="dfn" href="https://drafts.csswg.org/css-overflow-3/#scroll-container" id="ref-for-scroll-container②⓪">scroll container</a>, and</p>
     <li data-md>
      <p>if <var>d</var> is <code>up</code> or <code>down</code>, the computed value of the <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css-overflow-3/#propdef-overflow-y" id="ref-for-propdef-overflow-y">overflow-y</a> property is not <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-overflow-3/#valdef-overflow-hidden" id="ref-for-valdef-overflow-hidden">hidden</a>, and</p>
     <li data-md>
      <p>if <var>d</var> is <code>left</code> or <code>right</code>, the computed value of the <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css-overflow-3/#propdef-overflow-x" id="ref-for-propdef-overflow-x">overflow-x</a> property is not <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-overflow-3/#valdef-overflow-hidden" id="ref-for-valdef-overflow-hidden①">hidden</a>, and</p>
     <li data-md>
      <p><var>e</var> is not at the <a data-link-type="dfn" href="https://drafts.csswg.org/css-overscroll-behavior-1/#scroll-boundary" id="ref-for-scroll-boundary">scroll boundary</a> in the direction <var>d</var></p>
     <li data-md>
      <p><var>e</var> is not snapped to the last <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-scroll-snap-1/#valdef-scroll-snap-type-mandatory" id="ref-for-valdef-scroll-snap-type-mandatory">mandatory</a> snap point in direction <var>d</var></p>
    </ul>
   </div>
   <div class="algorithm" data-algorithm="to directionally scroll an element">
    <p class="issue" id="issue-00706fa4"><a class="self-link" href="#issue-00706fa4"></a> <a data-link-type="biblio" href="#biblio-cssom-view-1">[CSSOM-VIEW-1]</a> should probably define
how to perform a scroll in a given direction without an explicit position.
Until then, we roll our own. <a href="https://github.com/w3c/csswg-drafts/issues/2323">&lt;https://github.com/w3c/csswg-drafts/issues/2323></a></p>
    <p>To <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="directionally scroll an element | directionally scroll the element | be directionally scrolled" data-noexport id="directionally-scroll-an-element">directionally scroll an element</dfn> <var>e</var> in direction <var>dir</var>:</p>
    <ol>
     <li data-md>
      <p>Let <var>d</var> be a User Agent defined distance.</p>
     <li data-md>
      <p>Let <var>x</var> be <var>e</var>’s current scroll position on the x axis.</p>
     <li data-md>
      <p>Let <var>y</var> be <var>e</var>’s current scroll position on the y axis.</p>
     <li data-md>
      <p>Use the <a data-link-type="dfn" href="https://drafts.csswg.org/cssom-view-1/#scroll-an-element" id="ref-for-scroll-an-element">scroll an element</a> algorithm from <a data-link-type="biblio" href="#biblio-cssom-view-1">[CSSOM-VIEW-1]</a> on <var>e</var> to</p>
      <ul>
       <li data-md>
        <p>(<var>x</var>, <var>y</var> - <var>d</var>) if <var>dir</var> is <code>up</code></p>
       <li data-md>
        <p>(<var>x</var>, <var>y</var> + <var>d</var>) if <var>dir</var> is <code>down</code></p>
       <li data-md>
        <p>(<var>x</var> - <var>d</var>, <var>y</var>) if <var>dir</var> is <code>left</code></p>
       <li data-md>
        <p>(<var>x</var> + <var>d</var>, <var>y</var>) if <var>dir</var> is <code>right</code></p>
      </ul>
    </ol>
   </div>
   <h2 class="no-num heading settled" id="privsec"><span class="content"> Appendix B. Privacy and Security Considerations</span><a class="self-link" href="#privsec"></a></h2>
   <p>The specification contributors believe that
all known potential security risks associated with this specification
have been adequately addressed.
Further details are provided below.</p>
   <p>The TAG has developed a self-review questionaire
to help editors and Working Groups evaluate the risks introduced by their specifications.
Answers are provided below.</p>
   <dl>
    <dt>Does this specification deal with personally-identifiable information? 
    <dd>No. 
    <dt>Does this specification deal with high-value data? 
    <dd>No. 
    <dt>Does this specification introduce new state for an origin that persists across browsing sessions? 
    <dd>No. 
    <dt>Does this specification expose persistent, cross-origin state to the web? 
    <dd>No. 
    <dt>Does this specification expose any other data to an origin that it doesn’t currently have access to? 
    <dd>
      Mostly, no. 
     <p>The one exception identified would be in the following scenario:
    if the author uses `window.navigate` while the focus is in a cross origin iframe,
    if they don’t get an event at all it means that either there was something scrollable or focusable within the iframe,
    as the only case where they’d get an event is when the search didn’t find anything at all goes up the tree.</p>
     <p>This is so limited information that it does not seem it would introduces real a security risk,
    but it is as far as the editors can tell information that the author could not get could not get otherwise.</p>
    <dt>Does this specification enable new script execution/loading mechanisms? 
    <dd>No. 
    <dt>Does this specification allow an origin access to a user’s location? 
    <dd>No. 
    <dt>Does this specification allow an origin access to sensors on a user’s device? 
    <dd>No. 
    <dt>Does this specification allow an origin access to aspects of a user’s local computing environment? 
    <dd>No. 
    <dt>Does this specification allow an origin access to other devices? 
    <dd>No. 
    <dt>Does this specification allow an origin some measure of control over a user agent’s native UI? 
    <dd> No control is given over the appearance of the User Agent’s UI.
    Some control is given over how the User Agent performs spatial navigation,
    which may be considered part of its user interface.
    This is intentional, to let the author tailor the behavior of spatial navigation to their pages.
    To prevent malicious the author to interefere with the users' desire to control focus and navigate the document,
    this overriding mechanism is disabled by default for cross-origin iframes.
    See <a href="#policy-feature">§ 7 The navigation-override policy-controlled feature</a>. 
    <dt>Does this specification expose temporary identifiers to the web? 
    <dd>No. 
    <dt>Does this specification distinguish between behavior in first-party and third-party contexts? 
    <dd>No. 
    <dt>How should this specification work in the context of a user agent’s "incognito" mode? 
    <dd>No Difference. 
    <dt>Does this specification persist data to a user’s local device? 
    <dd>No. 
    <dt>Does this specification have a "Security Considerations" and "Privacy Considerations" section? 
    <dd>Yes, this is the section you are reading now. 
    <dt>Does this specification allow downgrading default security characteristics? 
    <dd>
      It does not allow downgrading any unrelated security mechanism. 
     <p>It **does** allow the author to opt into allowing
    the events needed to override the default behavior of spatial navigation
    in cross origin iframes they trust
    using <a data-link-type="biblio" href="#biblio-feature-policy">[feature-policy]</a>.
    See <a href="#policy-feature">§ 7 The navigation-override policy-controlled feature</a>.</p>
   </dl>
   <h2 class="no-num heading settled" id="ack"><span class="content">Acknowledgements</span><a class="self-link" href="#ack"></a></h2>
   <p>The editors of this specification would like to thank the following individuals for their feedback and contributions (in alphabetical order):</p>
   <ul>
    <li data-md>
     <p>Alice Boxhall</p>
    <li data-md>
     <p>Brian Kardell</p>
    <li data-md>
     <p>Elika Etemad</p>
    <li data-md>
     <p>Eric Seong</p>
    <li data-md>
     <p>Hugo Holgersson</p>
    <li data-md>
     <p>Hyojin Song</p>
    <li data-md>
     <p>Jeonghee Ahn</p>
    <li data-md>
     <p>Junho Seo</p>
    <li data-md>
     <p>Rob Dodson</p>
    <li data-md>
     <p>Seungcheon Baek</p>
   </ul>
   <h2 class="no-num heading settled" id="changes"><span class="content">Changes</span><a class="self-link" href="#changes"></a></h2>
   <p><em>This section is non-normative.</em></p>
   <p>The following changes were made since the <a href="https://www.w3.org/TR/2019/WD-css-nav-1-20190423/">23 April 2019 First Public Working Draft</a>.</p>
   <ul>
    <li data-md>
     <p>Changed the result of <code class="idl"><a data-link-type="idl" href="#dom-element-getspatialnavigationcontainer" id="ref-for-dom-element-getspatialnavigationcontainer④">getSpatialNavigationContainer()</a></code> to return the nearest <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers③⑥">spatial navigation container</a> ancestor</p>
    <li data-md>
     <p>Added <a class="property" data-link-type="propdesc" href="#propdef-spatial-navigation-function" id="ref-for-propdef-spatial-navigation-function②">spatial-navigation-function</a></p>
    <li data-md>
     <p>Added <a data-link-type="dfn" href="#update-the-search-origin" id="ref-for-update-the-search-origin①">updating the search origin</a> step</p>
    <li data-md>
     <p>Changed the IDL of <code class="idl"><a data-link-type="idl" href="#dom-element-spatialnavigationsearch" id="ref-for-dom-element-spatialnavigationsearch">spatialNavigationSearch()</a></code> as separating the dir attribute from <code class="idl"><a data-link-type="idl" href="#dictdef-spatialnavigationsearchoptions" id="ref-for-dictdef-spatialnavigationsearchoptions①">SpatialNavigationSearchOptions</a></code></p>
    <li data-md>
     <p>Made the focusable element fully overlapped with search origin which is not the <a data-link-type="dfn" href="#spatial-navigation-containers" id="ref-for-spatial-navigation-containers③⑦">spatial navigation container</a> as a candidate for fixing the unreachability</p>
   </ul>
  </main>
  <h2 class="no-ref no-num heading settled" id="conformance"><span class="content"> Conformance</span><a class="self-link" href="#conformance"></a></h2>
  <h3 class="heading settled" id="document-conventions"><span class="content"> Document conventions</span><a class="self-link" href="#document-conventions"></a></h3>
  <p>Conformance requirements are expressed with a combination of
	descriptive assertions and RFC 2119 terminology. The key words “MUST”,
	“MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”,
	“RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this
	document are to be interpreted as described in RFC 2119.
	However, for readability, these words do not appear in all uppercase
	letters in this specification. </p>
  <p>All of the text of this specification is normative except sections
	explicitly marked as non-normative, examples, and notes. <a data-link-type="biblio" href="#biblio-rfc2119">[RFC2119]</a> </p>
  <p>Examples in this specification are introduced with the words “for example”
	or are set apart from the normative text with <code>class="example"</code>,
	like this: </p>
  <div class="example" id="example-ae2b6bc0">
   <a class="self-link" href="#example-ae2b6bc0"></a> 
   <p>This is an example of an informative example. </p>
  </div>
  <p>Informative notes begin with the word “Note” and are set apart from the
	normative text with <code>class="note"</code>, like this: </p>
  <p class="note" role="note">Note, this is an informative note. </p>
  <p>Advisements are normative sections styled to evoke special attention and are
	set apart from other normative text with <code>&lt;strong class="advisement"></code>, like
	this: <strong class="advisement"> UAs MUST provide an accessible alternative. </strong> </p>
  <h3 class="heading settled" id="conform-classes"><span class="content"> Conformance classes</span><a class="self-link" href="#conform-classes"></a></h3>
  <p>Conformance to this specification
	is defined for three conformance classes: </p>
  <dl>
   <dt>style sheet 
   <dd>A <a href="http://www.w3.org/TR/CSS2/conform.html#style-sheet">CSS
			style sheet</a>. 
   <dt>renderer 
   <dd>A <a href="http://www.w3.org/TR/CSS2/conform.html#user-agent">UA</a> that interprets the semantics of a style sheet and renders
			documents that use them. 
   <dt>authoring tool 
   <dd>A <a href="http://www.w3.org/TR/CSS2/conform.html#user-agent">UA</a> that writes a style sheet. 
  </dl>
  <p>A style sheet is conformant to this specification
	if all of its statements that use syntax defined in this module are valid
	according to the generic CSS grammar and the individual grammars of each
	feature defined in this module. </p>
  <p>A renderer is conformant to this specification
	if, in addition to interpreting the style sheet as defined by the
	appropriate specifications, it supports all the features defined
	by this specification by parsing them correctly
	and rendering the document accordingly. However, the inability of a
	UA to correctly render a document due to limitations of the device
	does not make the UA non-conformant. (For example, a UA is not
	required to render color on a monochrome monitor.) </p>
  <p>An authoring tool is conformant to this specification
	if it writes style sheets that are syntactically correct according to the
	generic CSS grammar and the individual grammars of each feature in
	this module, and meet all other conformance requirements of style sheets
	as described in this module. </p>
  <h3 class="heading settled" id="conform-responsible"><span class="content"> Requirements for Responsible Implementation of CSS</span><a class="self-link" href="#conform-responsible"></a></h3>
  <p>The following sections define several conformance requirements
		for implementing CSS responsibly,
		in a way that promotes interoperability in the present and future. </p>
  <h4 class="heading settled" id="conform-partial"><span class="content"> Partial Implementations</span><a class="self-link" href="#conform-partial"></a></h4>
  <p>So that authors can exploit the forward-compatible parsing rules to assign fallback values, <strong>CSS renderers <em>must</em> treat as invalid
		(and <a href="http://www.w3.org/TR/CSS2/conform.html#ignore">ignore as appropriate</a>)
		any at-rules, properties, property values, keywords, and other syntactic constructs
		for which they have no usable level of support</strong>.
		In particular, user agents <em>must not</em> selectively ignore
		unsupported property values and honor supported values in a single multi-value property declaration:
		if any value is considered invalid (as unsupported values must be),
		CSS requires that the entire declaration be ignored. </p>
  <h4 class="heading settled" id="conform-future-proofing"><span class="content"> Implementations of Unstable and Proprietary Features</span><a class="self-link" href="#conform-future-proofing"></a></h4>
  <p>To avoid clashes with future stable CSS features,
		the CSSWG recommends <a href="http://www.w3.org/TR/CSS/#future-proofing">following best practices</a> for the implementation of <a href="http://www.w3.org/TR/CSS/#unstable">unstable</a> features and <a href="http://www.w3.org/TR/CSS/#proprietary-extension">proprietary extensions</a> to CSS. </p>
  <h4 class="heading settled" id="conform-testing"><span class="content"> Implementations of CR-level Features</span><a class="self-link" href="#conform-testing"></a></h4>
  <p>Once a specification reaches the Candidate Recommendation stage,
		implementers should release an <a data-link-type="dfn" href="http://www.w3.org/TR/CSS/#vendor-prefix">unprefixed</a> implementation
		of any CR-level feature they can demonstrate
		to be correctly implemented according to spec,
		and should avoid exposing a prefixed variant of that feature. </p>
  <p>To establish and maintain the interoperability of CSS across
		implementations, the CSS Working Group requests that non-experimental
		CSS renderers submit an implementation report (and, if necessary, the
		testcases used for that implementation report) to the W3C before
		releasing an unprefixed implementation of any CSS features. Testcases
		submitted to W3C are subject to review and correction by the CSS
		Working Group. </p>
  <p>
   Further information on submitting testcases and implementation reports
		can be found from on the CSS Working Group’s website at <a href="http://www.w3.org/Style/CSS/Test/">http://www.w3.org/Style/CSS/Test/</a>.
		Questions should be directed to the <a href="http://lists.w3.org/Archives/Public/public-css-testsuite">public-css-testsuite@w3.org</a> mailing list. 
<script src="https://www.w3.org/scripts/TR/2016/fixup.js"></script>
  </p>
  <h2 class="no-num no-ref heading settled" id="index"><span class="content">Index</span><a class="self-link" href="#index"></a></h2>
  <h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="content">Terms defined by this specification</span><a class="self-link" href="#index-defined-here"></a></h3>
  <ul class="index">
   <li><a href="#dom-focusableareasearchmode-all">"all"</a><span>, in §5.2</span>
   <li><a href="#at-risk">at-risk</a><span>, in §1</span>
   <li>
    auto
    <ul>
     <li><a href="#valdef-spatial-navigation-action-auto">value for spatial-navigation-action</a><span>, in §9.2</span>
     <li><a href="#valdef-spatial-navigation-contain-auto">value for spatial-navigation-contain</a><span>, in §9.1</span>
    </ul>
   <li><a href="#directionally-scroll-an-element">be directionally scrolled</a><span>, in §Unnumbered section</span>
   <li><a href="#boundary-box">boundary box</a><span>, in §8.1</span>
   <li><a href="#can-be-manually-scrolled">can be manually scrolled</a><span>, in §Unnumbered section</span>
   <li><a href="#can-be-manually-scrolled">can be scrolled manually</a><span>, in §Unnumbered section</span>
   <li><a href="#dom-spatialnavigationsearchoptions-candidates">candidates</a><span>, in §5.2</span>
   <li><a href="#can-be-manually-scrolled">cannot be manually scrolled</a><span>, in §Unnumbered section</span>
   <li><a href="#can-be-manually-scrolled">cannot be scrolled manually</a><span>, in §Unnumbered section</span>
   <li><a href="#dom-navigationevent-navigationevent">constructor(type)</a><span>, in §6.1</span>
   <li><a href="#dom-navigationevent-navigationevent">constructor(type, eventInitDict)</a><span>, in §6.1</span>
   <li><a href="#valdef-spatial-navigation-contain-contain">contain</a><span>, in §9.1</span>
   <li><a href="#dom-spatialnavigationsearchoptions-container">container</a><span>, in §5.2</span>
   <li>
    dir
    <ul>
     <li><a href="#dom-navigationevent-dir">attribute for NavigationEvent</a><span>, in §6.1</span>
     <li><a href="#dom-navigationeventinit-dir">dict-member for NavigationEventInit</a><span>, in §6.1</span>
    </ul>
   <li><a href="#directionally-scroll-an-element">directionally scroll an element</a><span>, in §Unnumbered section</span>
   <li><a href="#directionally-scroll-an-element">directionally scroll the element</a><span>, in §Unnumbered section</span>
   <li><a href="#dispatches-navbeforefocus-event">dispatches navbeforefocus event</a><span>, in §6.2.1</span>
   <li><a href="#dispatches-navnotarget-event">dispatches navnotarget event</a><span>, in §6.2.2</span>
   <li><a href="#dispatches-navbeforefocus-event">dispatching navbeforefocus event</a><span>, in §6.2.1</span>
   <li><a href="#dispatches-navnotarget-event">dispatching navnotarget event</a><span>, in §6.2.2</span>
   <li><a href="#dom-spatialnavigationdirection-down">"down"</a><span>, in §5.1</span>
   <li><a href="#find-focusable-areas">find focusable areas</a><span>, in §8.4</span>
   <li><a href="#find-focusable-areas">finding focusable areas</a><span>, in §8.4</span>
   <li><a href="#find-the-shortest-distance">finding the shortest distance</a><span>, in §8.4</span>
   <li><a href="#find-the-shortest-distance">find the shortest distance</a><span>, in §8.4</span>
   <li><a href="#valdef-spatial-navigation-action-focus">focus</a><span>, in §9.2</span>
   <li><a href="#dom-element-focusableareas">focusableAreas()</a><span>, in §5.2</span>
   <li><a href="#enumdef-focusableareasearchmode">FocusableAreaSearchMode</a><span>, in §5.2</span>
   <li><a href="#dictdef-focusableareasoption">FocusableAreasOption</a><span>, in §5.2</span>
   <li><a href="#dom-element-focusableareas">focusableAreas(option)</a><span>, in §5.2</span>
   <li><a href="#dom-element-getspatialnavigationcontainer">getSpatialNavigationContainer()</a><span>, in §5.2</span>
   <li><a href="#valdef-spatial-navigation-function-grid">grid</a><span>, in §9.3</span>
   <li><a href="#inside-area">inside area</a><span>, in §8.1</span>
   <li><a href="#dom-spatialnavigationdirection-left">"left"</a><span>, in §5.1</span>
   <li><a href="#dom-focusableareasoption-mode">mode</a><span>, in §5.2</span>
   <li><a href="#eventdef-navigationevent-navbeforefocus">navbeforefocus</a><span>, in §6.2.1</span>
   <li><a href="#dom-window-navigate">navigate(dir)</a><span>, in §5.1</span>
   <li><a href="#navigationevent">NavigationEvent</a><span>, in §6.1</span>
   <li><a href="#dictdef-navigationeventinit">NavigationEventInit</a><span>, in §6.1</span>
   <li><a href="#dom-navigationevent-navigationevent">NavigationEvent(type)</a><span>, in §6.1</span>
   <li><a href="#dom-navigationevent-navigationevent">NavigationEvent(type, eventInitDict)</a><span>, in §6.1</span>
   <li><a href="#navigation-override">navigation-override</a><span>, in §7</span>
   <li><a href="#eventdef-navigationevent-navnotarget">navnotarget</a><span>, in §6.2.2</span>
   <li><a href="#valdef-spatial-navigation-function-normal">normal</a><span>, in §9.3</span>
   <li>
    relatedTarget
    <ul>
     <li><a href="#dom-navigationevent-relatedtarget">attribute for NavigationEvent</a><span>, in §6.1</span>
     <li><a href="#dom-navigationeventinit-relatedtarget">dict-member for NavigationEventInit</a><span>, in §6.1</span>
    </ul>
   <li><a href="#dom-spatialnavigationdirection-right">"right"</a><span>, in §5.1</span>
   <li><a href="#valdef-spatial-navigation-action-scroll">scroll</a><span>, in §9.2</span>
   <li><a href="#search-origin">search origin</a><span>, in §8.1</span>
   <li><a href="#select-the-best-candidate">selecting the best candidate</a><span>, in §8.4</span>
   <li><a href="#select-the-best-candidate">select the best candidate</a><span>, in §8.4</span>
   <li><a href="#set-the-search-origin">set the search origin</a><span>, in §8.4</span>
   <li><a href="#set-the-search-origin">setting the search origin</a><span>, in §8.4</span>
   <li><a href="#spatial-navigation">spatialNavigation</a><span>, in §1</span>
   <li><a href="#spatial-navigation">spatial navigation</a><span>, in §1</span>
   <li><a href="#propdef-spatial-navigation-action">spatial-navigation-action</a><span>, in §9.2</span>
   <li><a href="#propdef-spatial-navigation-contain">spatial-navigation-contain</a><span>, in §9.1</span>
   <li><a href="#spatial-navigation-containers">spatial navigation containers</a><span>, in §8.2</span>
   <li><a href="#enumdef-spatialnavigationdirection">SpatialNavigationDirection</a><span>, in §5.1</span>
   <li><a href="#propdef-spatial-navigation-function">spatial-navigation-function</a><span>, in §9.3</span>
   <li><a href="#dom-element-spatialnavigationsearch">spatialNavigationSearch(dir)</a><span>, in §5.2</span>
   <li><a href="#dom-element-spatialnavigationsearch">spatialNavigationSearch(dir, options)</a><span>, in §5.2</span>
   <li><a href="#dictdef-spatialnavigationsearchoptions">SpatialNavigationSearchOptions</a><span>, in §5.2</span>
   <li><a href="#dom-element-spatialnavigationsearch-options">spatialNavigationSearch(options)</a><span>, in §5.2</span>
   <li><a href="#spatial-navigation-starting-point">spatial navigation starting point</a><span>, in §8.1</span>
   <li><a href="#spatial-navigation-steps">spatial navigation steps</a><span>, in §8.3</span>
   <li><a href="#dom-spatialnavigationdirection-up">"up"</a><span>, in §5.1</span>
   <li><a href="#update-the-search-origin">update the search origin</a><span>, in §8.4</span>
   <li><a href="#update-the-search-origin">updating the search origin</a><span>, in §8.4</span>
   <li><a href="#dom-focusableareasearchmode-visible">"visible"</a><span>, in §5.2</span>
  </ul>
  <aside class="dfn-panel" data-for="term-for-box-fragment">
   <a href="https://drafts.csswg.org/css-break-4/#box-fragment">https://drafts.csswg.org/css-break-4/#box-fragment</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-box-fragment">8.1. 
Glossary</a> <a href="#ref-for-box-fragment①">(2)</a>
    <li><a href="#ref-for-box-fragment②">8.4. 
Focus Navigation Heuristics</a> <a href="#ref-for-box-fragment③">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-propdef-all">
   <a href="https://drafts.csswg.org/css-cascade-4/#propdef-all">https://drafts.csswg.org/css-cascade-4/#propdef-all</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-propdef-all">5.2. 
Low level APIs</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-box">
   <a href="https://drafts.csswg.org/css-display-3/#box">https://drafts.csswg.org/css-display-3/#box</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-box">8.1. 
Glossary</a> <a href="#ref-for-box①">(2)</a>
    <li><a href="#ref-for-box②">8.4. 
Focus Navigation Heuristics</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-principal-box">
   <a href="https://drafts.csswg.org/css-display-3/#principal-box">https://drafts.csswg.org/css-display-3/#principal-box</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-principal-box">Appendix A. Scroll extensions</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-valdef-overflow-hidden">
   <a href="https://drafts.csswg.org/css-overflow-3/#valdef-overflow-hidden">https://drafts.csswg.org/css-overflow-3/#valdef-overflow-hidden</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-valdef-overflow-hidden">Appendix A. Scroll extensions</a> <a href="#ref-for-valdef-overflow-hidden①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-propdef-overflow-x">
   <a href="https://drafts.csswg.org/css-overflow-3/#propdef-overflow-x">https://drafts.csswg.org/css-overflow-3/#propdef-overflow-x</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-propdef-overflow-x">Appendix A. Scroll extensions</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-propdef-overflow-y">
   <a href="https://drafts.csswg.org/css-overflow-3/#propdef-overflow-y">https://drafts.csswg.org/css-overflow-3/#propdef-overflow-y</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-propdef-overflow-y">Appendix A. Scroll extensions</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-scroll-container">
   <a href="https://drafts.csswg.org/css-overflow-3/#scroll-container">https://drafts.csswg.org/css-overflow-3/#scroll-container</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-scroll-container">6.2.2. 
navnotarget</a> <a href="#ref-for-scroll-container①">(2)</a>
    <li><a href="#ref-for-scroll-container②">8.1. 
Glossary</a> <a href="#ref-for-scroll-container③">(2)</a>
    <li><a href="#ref-for-scroll-container④">8.2. 
Groupings of elements</a>
    <li><a href="#ref-for-scroll-container⑤">8.3. 
Navigation</a> <a href="#ref-for-scroll-container⑥">(2)</a> <a href="#ref-for-scroll-container⑦">(3)</a>
    <li><a href="#ref-for-scroll-container⑧">9.1. 
Creating additional spatial navigation containers: the spatial-navigation-contain property</a>
    <li><a href="#ref-for-scroll-container⑨">9.2. 
Controlling the interaction with scrolling: the spatial-navigation-action property</a> <a href="#ref-for-scroll-container①⓪">(2)</a> <a href="#ref-for-scroll-container①①">(3)</a> <a href="#ref-for-scroll-container①②">(4)</a> <a href="#ref-for-scroll-container①③">(5)</a> <a href="#ref-for-scroll-container①④">(6)</a> <a href="#ref-for-scroll-container①⑤">(7)</a> <a href="#ref-for-scroll-container①⑥">(8)</a> <a href="#ref-for-scroll-container①⑦">(9)</a> <a href="#ref-for-scroll-container①⑧">(10)</a> <a href="#ref-for-scroll-container①⑨">(11)</a>
    <li><a href="#ref-for-scroll-container②⓪">Appendix A. Scroll extensions</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-scrollport">
   <a href="https://drafts.csswg.org/css-overflow-3/#scrollport">https://drafts.csswg.org/css-overflow-3/#scrollport</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-scrollport">3. 
Overview</a> <a href="#ref-for-scrollport①">(2)</a> <a href="#ref-for-scrollport②">(3)</a>
    <li><a href="#ref-for-scrollport③">5.2. 
Low level APIs</a>
    <li><a href="#ref-for-scrollport④">6.2.2. 
navnotarget</a>
    <li><a href="#ref-for-scrollport⑤">9.2. 
Controlling the interaction with scrolling: the spatial-navigation-action property</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-relative-position">
   <a href="https://drafts.csswg.org/css-position-3/#relative-position">https://drafts.csswg.org/css-position-3/#relative-position</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-relative-position">8.4. 
Focus Navigation Heuristics</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-valdef-scroll-snap-type-mandatory">
   <a href="https://drafts.csswg.org/css-scroll-snap-1/#valdef-scroll-snap-type-mandatory">https://drafts.csswg.org/css-scroll-snap-1/#valdef-scroll-snap-type-mandatory</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-valdef-scroll-snap-type-mandatory">Appendix A. Scroll extensions</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-optimal-viewing-region">
   <a href="https://drafts.csswg.org/css-scroll-snap-1/#optimal-viewing-region">https://drafts.csswg.org/css-scroll-snap-1/#optimal-viewing-region</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-optimal-viewing-region">8.1. 
Glossary</a> <a href="#ref-for-optimal-viewing-region①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-mult-one-plus">
   <a href="https://drafts.csswg.org/css-values-4/#mult-one-plus">https://drafts.csswg.org/css-values-4/#mult-one-plus</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-mult-one-plus">8.4. 
Focus Navigation Heuristics</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-comb-one">
   <a href="https://drafts.csswg.org/css-values-4/#comb-one">https://drafts.csswg.org/css-values-4/#comb-one</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-comb-one">9.1. 
Creating additional spatial navigation containers: the spatial-navigation-contain property</a>
    <li><a href="#ref-for-comb-one①">9.2. 
Controlling the interaction with scrolling: the spatial-navigation-action property</a> <a href="#ref-for-comb-one②">(2)</a>
    <li><a href="#ref-for-comb-one③">9.3. 
Selecting the navigation algorithm: the spatial-navigation-function property</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-x14">
   <a href="https://drafts.csswg.org/css2/box.html#x14">https://drafts.csswg.org/css2/box.html#x14</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-x14">8.1. 
Glossary</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-painting-order">
   <a href="https://drafts.csswg.org/css2/zindex.html#painting-order">https://drafts.csswg.org/css2/zindex.html#painting-order</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-painting-order">8.4. 
Focus Navigation Heuristics</a> <a href="#ref-for-painting-order①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-scroll-an-element">
   <a href="https://drafts.csswg.org/cssom-view-1/#scroll-an-element">https://drafts.csswg.org/cssom-view-1/#scroll-an-element</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-scroll-an-element">Appendix A. Scroll extensions</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-element">
   <a href="https://dom.spec.whatwg.org/#element">https://dom.spec.whatwg.org/#element</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-element">5.2. 
Low level APIs</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-event">
   <a href="https://dom.spec.whatwg.org/#event">https://dom.spec.whatwg.org/#event</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-event">6.2.1. 
navbeforefocus</a>
    <li><a href="#ref-for-event①">6.2.2. 
navnotarget</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-eventtarget">
   <a href="https://dom.spec.whatwg.org/#eventtarget">https://dom.spec.whatwg.org/#eventtarget</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-eventtarget">6.1. 
Interface NavigationEvent</a> <a href="#ref-for-eventtarget①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-node">
   <a href="https://dom.spec.whatwg.org/#node">https://dom.spec.whatwg.org/#node</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-node">5.2. 
Low level APIs</a> <a href="#ref-for-node①">(2)</a> <a href="#ref-for-node②">(3)</a> <a href="#ref-for-node③">(4)</a> <a href="#ref-for-node④">(5)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-canceled-flag">
   <a href="https://dom.spec.whatwg.org/#canceled-flag">https://dom.spec.whatwg.org/#canceled-flag</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-canceled-flag">4. 
Triggering Spatial Navigation</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-concept-document">
   <a href="https://dom.spec.whatwg.org/#concept-document">https://dom.spec.whatwg.org/#concept-document</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-concept-document">5.2. 
Low level APIs</a>
    <li><a href="#ref-for-concept-document①">8.1. 
Glossary</a>
    <li><a href="#ref-for-concept-document②">8.3. 
Navigation</a> <a href="#ref-for-concept-document③">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-document-element">
   <a href="https://dom.spec.whatwg.org/#document-element">https://dom.spec.whatwg.org/#document-element</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-document-element">8.3. 
Navigation</a> <a href="#ref-for-document-element①">(2)</a> <a href="#ref-for-document-element②">(3)</a> <a href="#ref-for-document-element③">(4)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-boundary-point-node">
   <a href="https://dom.spec.whatwg.org/#boundary-point-node">https://dom.spec.whatwg.org/#boundary-point-node</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-boundary-point-node">8.3. 
Navigation</a> <a href="#ref-for-boundary-point-node①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-concept-node-document">
   <a href="https://dom.spec.whatwg.org/#concept-node-document">https://dom.spec.whatwg.org/#concept-node-document</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-concept-node-document">6.2.1. 
navbeforefocus</a>
    <li><a href="#ref-for-concept-node-document①">6.2.2. 
navnotarget</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-dom-event-preventdefault">
   <a href="https://dom.spec.whatwg.org/#dom-event-preventdefault">https://dom.spec.whatwg.org/#dom-event-preventdefault</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-event-preventdefault">3. 
Overview</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-dom-event-target">
   <a href="https://dom.spec.whatwg.org/#dom-event-target">https://dom.spec.whatwg.org/#dom-event-target</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-event-target">6.2.1. 
navbeforefocus</a>
    <li><a href="#ref-for-dom-event-target①">6.2.2. 
navnotarget</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-default-allowlist">
   <a href="https://w3c.github.io/webappsec-feature-policy/#default-allowlist">https://w3c.github.io/webappsec-feature-policy/#default-allowlist</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-allowlist">7. 
The navigation-override policy-controlled feature</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-policy-controlled-feature">
   <a href="https://w3c.github.io/webappsec-feature-policy/#policy-controlled-feature">https://w3c.github.io/webappsec-feature-policy/#policy-controlled-feature</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-policy-controlled-feature">7. 
The navigation-override policy-controlled feature</a> <a href="#ref-for-policy-controlled-feature①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-window">
   <a href="https://html.spec.whatwg.org/multipage/window-object.html#window">https://html.spec.whatwg.org/multipage/window-object.html#window</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-window">5.1. 
Triggering Navigation Programmatically</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-active-document">
   <a href="https://html.spec.whatwg.org/multipage/browsers.html#active-document">https://html.spec.whatwg.org/multipage/browsers.html#active-document</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-active-document">6.2.1. 
navbeforefocus</a>
    <li><a href="#ref-for-active-document①">6.2.2. 
navnotarget</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-concept-element-disabled">
   <a href="https://html.spec.whatwg.org/multipage/semantics-other.html#concept-element-disabled">https://html.spec.whatwg.org/multipage/semantics-other.html#concept-element-disabled</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-concept-element-disabled">8.4. 
Focus Navigation Heuristics</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-being-rendered">
   <a href="https://html.spec.whatwg.org/multipage/rendering.html#being-rendered">https://html.spec.whatwg.org/multipage/rendering.html#being-rendered</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-being-rendered">8.4. 
Focus Navigation Heuristics</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-browsing-context">
   <a href="https://html.spec.whatwg.org/multipage/browsers.html#browsing-context">https://html.spec.whatwg.org/multipage/browsers.html#browsing-context</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-browsing-context">8.1. 
Glossary</a>
    <li><a href="#ref-for-browsing-context①">8.2. 
Groupings of elements</a>
    <li><a href="#ref-for-browsing-context②">9.1. 
Creating additional spatial navigation containers: the spatial-navigation-contain property</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-browsing-context-container">
   <a href="https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-container">https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-container</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-browsing-context-container">8.3. 
Navigation</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-currently-focused-area-of-a-top-level-browsing-context">
   <a href="https://html.spec.whatwg.org/multipage/interaction.html#currently-focused-area-of-a-top-level-browsing-context">https://html.spec.whatwg.org/multipage/interaction.html#currently-focused-area-of-a-top-level-browsing-context</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-currently-focused-area-of-a-top-level-browsing-context">8.4. 
Focus Navigation Heuristics</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-dom-anchor">
   <a href="https://html.spec.whatwg.org/multipage/interaction.html#dom-anchor">https://html.spec.whatwg.org/multipage/interaction.html#dom-anchor</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-anchor">8.4. 
Focus Navigation Heuristics</a> <a href="#ref-for-dom-anchor①">(2)</a> <a href="#ref-for-dom-anchor②">(3)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-expressly-inert">
   <a href="https://html.spec.whatwg.org/multipage/interaction.html#expressly-inert">https://html.spec.whatwg.org/multipage/interaction.html#expressly-inert</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-expressly-inert">8.4. 
Focus Navigation Heuristics</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-dom-focus">
   <a href="https://html.spec.whatwg.org/multipage/interaction.html#dom-focus">https://html.spec.whatwg.org/multipage/interaction.html#dom-focus</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-focus">3. 
Overview</a>
    <li><a href="#ref-for-dom-focus①">6.2.2. 
navnotarget</a>
    <li><a href="#ref-for-dom-focus②">9.2. 
Controlling the interaction with scrolling: the spatial-navigation-action property</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-focusable-area">
   <a href="https://html.spec.whatwg.org/multipage/interaction.html#focusable-area">https://html.spec.whatwg.org/multipage/interaction.html#focusable-area</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-focusable-area">8.1. 
Glossary</a> <a href="#ref-for-focusable-area①">(2)</a>
    <li><a href="#ref-for-focusable-area②">8.4. 
Focus Navigation Heuristics</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-focusing-steps">
   <a href="https://html.spec.whatwg.org/multipage/interaction.html#focusing-steps">https://html.spec.whatwg.org/multipage/interaction.html#focusing-steps</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-focusing-steps">8.3. 
Navigation</a> <a href="#ref-for-focusing-steps①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-nested-browsing-context">
   <a href="https://html.spec.whatwg.org/multipage/browsers.html#nested-browsing-context">https://html.spec.whatwg.org/multipage/browsers.html#nested-browsing-context</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-nested-browsing-context">8.3. 
Navigation</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-concept-origin">
   <a href="https://html.spec.whatwg.org/multipage/origin.html#concept-origin">https://html.spec.whatwg.org/multipage/origin.html#concept-origin</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-concept-origin">6.2.1. 
navbeforefocus</a>
    <li><a href="#ref-for-concept-origin①">6.2.2. 
navnotarget</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-nodes-are-removed">
   <a href="https://html.spec.whatwg.org/multipage/infrastructure.html#nodes-are-removed">https://html.spec.whatwg.org/multipage/infrastructure.html#nodes-are-removed</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-nodes-are-removed">8.4. 
Focus Navigation Heuristics</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-sequential-focus-navigation-order">
   <a href="https://html.spec.whatwg.org/multipage/interaction.html#sequential-focus-navigation-order">https://html.spec.whatwg.org/multipage/interaction.html#sequential-focus-navigation-order</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-sequential-focus-navigation-order">8.4. 
Focus Navigation Heuristics</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-sequential-focus-navigation-starting-point">
   <a href="https://html.spec.whatwg.org/multipage/interaction.html#sequential-focus-navigation-starting-point">https://html.spec.whatwg.org/multipage/interaction.html#sequential-focus-navigation-starting-point</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-sequential-focus-navigation-starting-point">8.1. 
Glossary</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-attr-tabindex">
   <a href="https://html.spec.whatwg.org/multipage/interaction.html#attr-tabindex">https://html.spec.whatwg.org/multipage/interaction.html#attr-tabindex</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-attr-tabindex">8.4. 
Focus Navigation Heuristics</a> <a href="#ref-for-attr-tabindex①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-the-body-element-2">
   <a href="https://html.spec.whatwg.org/multipage/dom.html#the-body-element-2">https://html.spec.whatwg.org/multipage/dom.html#the-body-element-2</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-the-body-element-2">6.2.1. 
navbeforefocus</a>
    <li><a href="#ref-for-the-body-element-2①">6.2.2. 
navnotarget</a>
    <li><a href="#ref-for-the-body-element-2②">8.3. 
Navigation</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-top-level-browsing-context">
   <a href="https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context">https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-top-level-browsing-context">6.2.1. 
navbeforefocus</a>
    <li><a href="#ref-for-top-level-browsing-context①">6.2.2. 
navnotarget</a>
    <li><a href="#ref-for-top-level-browsing-context②">8.2. 
Groupings of elements</a>
    <li><a href="#ref-for-top-level-browsing-context③">8.3. 
Navigation</a>
    <li><a href="#ref-for-top-level-browsing-context④">9.1. 
Creating additional spatial navigation containers: the spatial-navigation-contain property</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-assert">
   <a href="https://infra.spec.whatwg.org/#assert">https://infra.spec.whatwg.org/#assert</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-assert">8.3. 
Navigation</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-list-empty">
   <a href="https://infra.spec.whatwg.org/#list-empty">https://infra.spec.whatwg.org/#list-empty</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-list-empty">8.4. 
Focus Navigation Heuristics</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-list-remove">
   <a href="https://infra.spec.whatwg.org/#list-remove">https://infra.spec.whatwg.org/#list-remove</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-list-remove">8.4. 
Focus Navigation Heuristics</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-ordered-set">
   <a href="https://infra.spec.whatwg.org/#ordered-set">https://infra.spec.whatwg.org/#ordered-set</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ordered-set">8.4. 
Focus Navigation Heuristics</a> <a href="#ref-for-ordered-set①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-scroll-boundary">
   <a href="https://drafts.csswg.org/css-overscroll-behavior-1/#scroll-boundary">https://drafts.csswg.org/css-overscroll-behavior-1/#scroll-boundary</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-scroll-boundary">Appendix A. Scroll extensions</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-keyboardevent">
   <a href="https://www.w3.org/TR/uievents/#keyboardevent">https://www.w3.org/TR/uievents/#keyboardevent</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-keyboardevent">6.2.1. 
navbeforefocus</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-uievent">
   <a href="https://www.w3.org/TR/uievents/#uievent">https://www.w3.org/TR/uievents/#uievent</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-uievent">4. 
Triggering Spatial Navigation</a>
    <li><a href="#ref-for-uievent①">6.1. 
Interface NavigationEvent</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-dictdef-uieventinit">
   <a href="https://www.w3.org/TR/uievents/#dictdef-uieventinit">https://www.w3.org/TR/uievents/#dictdef-uieventinit</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dictdef-uieventinit">6.1. 
Interface NavigationEvent</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-event-target">
   <a href="https://w3c.github.io/uievents/#event-target">https://w3c.github.io/uievents/#event-target</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-event-target">6.2.1. 
navbeforefocus</a>
    <li><a href="#ref-for-event-target①">6.2.2. 
navnotarget</a> <a href="#ref-for-event-target②">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-dom-keyboardevent-key">
   <a href="https://www.w3.org/TR/uievents/#dom-keyboardevent-key">https://www.w3.org/TR/uievents/#dom-keyboardevent-key</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-keyboardevent-key">6.2.1. 
navbeforefocus</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-keydown">
   <a href="https://w3c.github.io/uievents/#keydown">https://w3c.github.io/uievents/#keydown</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-keydown">4. 
Triggering Spatial Navigation</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-idl-DOMString">
   <a href="https://heycam.github.io/webidl/#idl-DOMString">https://heycam.github.io/webidl/#idl-DOMString</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-idl-DOMString">6.1. 
Interface NavigationEvent</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-Exposed">
   <a href="https://heycam.github.io/webidl/#Exposed">https://heycam.github.io/webidl/#Exposed</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-Exposed">6.1. 
Interface NavigationEvent</a>
   </ul>
  </aside>
  <h3 class="no-num no-ref heading settled" id="index-defined-elsewhere"><span class="content">Terms defined by reference</span><a class="self-link" href="#index-defined-elsewhere"></a></h3>
  <ul class="index">
   <li>
    <a data-link-type="biblio">[css-break-4]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-box-fragment" style="color:initial">box fragment</span>
    </ul>
   <li>
    <a data-link-type="biblio">[css-cascade-4]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-propdef-all" style="color:initial">all</span>
    </ul>
   <li>
    <a data-link-type="biblio">[css-display-3]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-box" style="color:initial">box</span>
     <li><span class="dfn-paneled" id="term-for-principal-box" style="color:initial">principal box</span>
    </ul>
   <li>
    <a data-link-type="biblio">[CSS-OVERFLOW-3]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-valdef-overflow-hidden" style="color:initial">hidden</span>
     <li><span class="dfn-paneled" id="term-for-propdef-overflow-x" style="color:initial">overflow-x</span>
     <li><span class="dfn-paneled" id="term-for-propdef-overflow-y" style="color:initial">overflow-y</span>
     <li><span class="dfn-paneled" id="term-for-scroll-container" style="color:initial">scroll container</span>
     <li><span class="dfn-paneled" id="term-for-scrollport" style="color:initial">scrollport</span>
    </ul>
   <li>
    <a data-link-type="biblio">[css-position-3]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-relative-position" style="color:initial">relative position</span>
    </ul>
   <li>
    <a data-link-type="biblio">[CSS-SCROLL-SNAP-1]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-valdef-scroll-snap-type-mandatory" style="color:initial">mandatory</span>
     <li><span class="dfn-paneled" id="term-for-optimal-viewing-region" style="color:initial">optimal viewing region</span>
    </ul>
   <li>
    <a data-link-type="biblio">[css-values-4]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-mult-one-plus" style="color:initial">+</span>
     <li><span class="dfn-paneled" id="term-for-comb-one" style="color:initial">|</span>
    </ul>
   <li>
    <a data-link-type="biblio">[CSS2]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-x14" style="color:initial">border box</span>
     <li><span class="dfn-paneled" id="term-for-painting-order" style="color:initial">painting order</span>
    </ul>
   <li>
    <a data-link-type="biblio">[CSSOM-VIEW-1]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-scroll-an-element" style="color:initial">scroll an element</span>
    </ul>
   <li>
    <a data-link-type="biblio">[DOM]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-element" style="color:initial">Element</span>
     <li><span class="dfn-paneled" id="term-for-event" style="color:initial">Event</span>
     <li><span class="dfn-paneled" id="term-for-eventtarget" style="color:initial">EventTarget</span>
     <li><span class="dfn-paneled" id="term-for-node" style="color:initial">Node</span>
     <li><span class="dfn-paneled" id="term-for-canceled-flag" style="color:initial">canceled flag</span>
     <li><span class="dfn-paneled" id="term-for-concept-document" style="color:initial">document</span>
     <li><span class="dfn-paneled" id="term-for-document-element" style="color:initial">document element</span>
     <li><span class="dfn-paneled" id="term-for-boundary-point-node" style="color:initial">node</span>
     <li><span class="dfn-paneled" id="term-for-concept-node-document" style="color:initial">node document</span>
     <li><span class="dfn-paneled" id="term-for-dom-event-preventdefault" style="color:initial">preventDefault()</span>
     <li><span class="dfn-paneled" id="term-for-dom-event-target" style="color:initial">target</span>
    </ul>
   <li>
    <a data-link-type="biblio">[feature-policy]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-default-allowlist" style="color:initial">default allowlist</span>
     <li><span class="dfn-paneled" id="term-for-policy-controlled-feature" style="color:initial">policy-controlled feature</span>
    </ul>
   <li>
    <a data-link-type="biblio">[HTML]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-window" style="color:initial">Window</span>
     <li><span class="dfn-paneled" id="term-for-active-document" style="color:initial">active document</span>
     <li><span class="dfn-paneled" id="term-for-concept-element-disabled" style="color:initial">actually disabled</span>
     <li><span class="dfn-paneled" id="term-for-being-rendered" style="color:initial">being rendered</span>
     <li><span class="dfn-paneled" id="term-for-browsing-context" style="color:initial">browsing context</span>
     <li><span class="dfn-paneled" id="term-for-browsing-context-container" style="color:initial">browsing context container</span>
     <li><span class="dfn-paneled" id="term-for-currently-focused-area-of-a-top-level-browsing-context" style="color:initial">currently focused area of a top-level browsing context</span>
     <li><span class="dfn-paneled" id="term-for-dom-anchor" style="color:initial">dom anchor</span>
     <li><span class="dfn-paneled" id="term-for-expressly-inert" style="color:initial">expressly inert</span>
     <li><span class="dfn-paneled" id="term-for-dom-focus" style="color:initial">focus()</span>
     <li><span class="dfn-paneled" id="term-for-focusable-area" style="color:initial">focusable area</span>
     <li><span class="dfn-paneled" id="term-for-focusing-steps" style="color:initial">focusing steps</span>
     <li><span class="dfn-paneled" id="term-for-nested-browsing-context" style="color:initial">nested browsing context</span>
     <li><span class="dfn-paneled" id="term-for-concept-origin" style="color:initial">origin</span>
     <li><span class="dfn-paneled" id="term-for-nodes-are-removed" style="color:initial">removed</span>
     <li><span class="dfn-paneled" id="term-for-sequential-focus-navigation-order" style="color:initial">sequential focus navigation order</span>
     <li><span class="dfn-paneled" id="term-for-sequential-focus-navigation-starting-point" style="color:initial">sequential focus navigation starting point</span>
     <li><span class="dfn-paneled" id="term-for-attr-tabindex" style="color:initial">tabindex</span>
     <li><span class="dfn-paneled" id="term-for-the-body-element-2" style="color:initial">the body element</span>
     <li><span class="dfn-paneled" id="term-for-top-level-browsing-context" style="color:initial">top-level browsing context</span>
    </ul>
   <li>
    <a data-link-type="biblio">[infra]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-assert" style="color:initial">assert</span>
     <li><span class="dfn-paneled" id="term-for-list-empty" style="color:initial">empty</span>
     <li><span class="dfn-paneled" id="term-for-list-remove" style="color:initial">remove</span>
     <li><span class="dfn-paneled" id="term-for-ordered-set" style="color:initial">set</span>
    </ul>
   <li>
    <a data-link-type="biblio">[overscroll-behavior]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-scroll-boundary" style="color:initial">scroll boundary</span>
    </ul>
   <li>
    <a data-link-type="biblio">[uievents]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-keyboardevent" style="color:initial">KeyboardEvent</span>
     <li><span class="dfn-paneled" id="term-for-uievent" style="color:initial">UIEvent</span>
     <li><span class="dfn-paneled" id="term-for-dictdef-uieventinit" style="color:initial">UIEventInit</span>
     <li><span class="dfn-paneled" id="term-for-event-target" style="color:initial">event target</span>
     <li><span class="dfn-paneled" id="term-for-dom-keyboardevent-key" style="color:initial">key</span>
     <li><span class="dfn-paneled" id="term-for-keydown" style="color:initial">keydown</span>
    </ul>
   <li>
    <a data-link-type="biblio">[WebIDL]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-idl-DOMString" style="color:initial">DOMString</span>
     <li><span class="dfn-paneled" id="term-for-Exposed" style="color:initial">Exposed</span>
    </ul>
  </ul>
  <h2 class="no-num no-ref heading settled" id="references"><span class="content">References</span><a class="self-link" href="#references"></a></h2>
  <h3 class="no-num no-ref heading settled" id="normative"><span class="content">Normative References</span><a class="self-link" href="#normative"></a></h3>
  <dl>
   <dt id="biblio-css-break-4">[CSS-BREAK-4]
   <dd>Rossen Atanassov; Elika Etemad. <a href="https://www.w3.org/TR/css-break-4/">CSS Fragmentation Module Level 4</a>. 18 December 2018. WD. URL: <a href="https://www.w3.org/TR/css-break-4/">https://www.w3.org/TR/css-break-4/</a>
   <dt id="biblio-css-cascade-4">[CSS-CASCADE-4]
   <dd>Elika Etemad; Tab Atkins Jr.. <a href="https://www.w3.org/TR/css-cascade-4/">CSS Cascading and Inheritance Level 4</a>. 28 August 2018. CR. URL: <a href="https://www.w3.org/TR/css-cascade-4/">https://www.w3.org/TR/css-cascade-4/</a>
   <dt id="biblio-css-display-3">[CSS-DISPLAY-3]
   <dd>Tab Atkins Jr.; Elika Etemad. <a href="https://www.w3.org/TR/css-display-3/">CSS Display Module Level 3</a>. 28 August 2018. CR. URL: <a href="https://www.w3.org/TR/css-display-3/">https://www.w3.org/TR/css-display-3/</a>
   <dt id="biblio-css-overflow-3">[CSS-OVERFLOW-3]
   <dd>David Baron; Elika Etemad; Florian Rivoal. <a href="https://www.w3.org/TR/css-overflow-3/">CSS Overflow Module Level 3</a>. 31 July 2018. WD. URL: <a href="https://www.w3.org/TR/css-overflow-3/">https://www.w3.org/TR/css-overflow-3/</a>
   <dt id="biblio-css-position-3">[CSS-POSITION-3]
   <dd>Rossen Atanassov; Arron Eicholz. <a href="https://www.w3.org/TR/css-position-3/">CSS Positioned Layout Module Level 3</a>. 17 May 2016. WD. URL: <a href="https://www.w3.org/TR/css-position-3/">https://www.w3.org/TR/css-position-3/</a>
   <dt id="biblio-css-scroll-snap-1">[CSS-SCROLL-SNAP-1]
   <dd>Matt Rakow; et al. <a href="https://www.w3.org/TR/css-scroll-snap-1/">CSS Scroll Snap Module Level 1</a>. 19 March 2019. CR. URL: <a href="https://www.w3.org/TR/css-scroll-snap-1/">https://www.w3.org/TR/css-scroll-snap-1/</a>
   <dt id="biblio-css-values-4">[CSS-VALUES-4]
   <dd>Tab Atkins Jr.; Elika Etemad. <a href="https://www.w3.org/TR/css-values-4/">CSS Values and Units Module Level 4</a>. 31 January 2019. WD. URL: <a href="https://www.w3.org/TR/css-values-4/">https://www.w3.org/TR/css-values-4/</a>
   <dt id="biblio-css2">[CSS2]
   <dd>Bert Bos; et al. <a href="https://www.w3.org/TR/CSS2/">Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification</a>. 7 June 2011. REC. URL: <a href="https://www.w3.org/TR/CSS2/">https://www.w3.org/TR/CSS2/</a>
   <dt id="biblio-cssom-view-1">[CSSOM-VIEW-1]
   <dd>Simon Pieters. <a href="https://www.w3.org/TR/cssom-view-1/">CSSOM View Module</a>. 17 March 2016. WD. URL: <a href="https://www.w3.org/TR/cssom-view-1/">https://www.w3.org/TR/cssom-view-1/</a>
   <dt id="biblio-dom">[DOM]
   <dd>Anne van Kesteren. <a href="https://dom.spec.whatwg.org/">DOM Standard</a>. Living Standard. URL: <a href="https://dom.spec.whatwg.org/">https://dom.spec.whatwg.org/</a>
   <dt id="biblio-feature-policy">[FEATURE-POLICY]
   <dd>Ian Clelland. <a href="https://www.w3.org/TR/feature-policy-1/">Feature Policy</a>. 16 April 2019. WD. URL: <a href="https://www.w3.org/TR/feature-policy-1/">https://www.w3.org/TR/feature-policy-1/</a>
   <dt id="biblio-html">[HTML]
   <dd>Anne van Kesteren; et al. <a href="https://html.spec.whatwg.org/multipage/">HTML Standard</a>. Living Standard. URL: <a href="https://html.spec.whatwg.org/multipage/">https://html.spec.whatwg.org/multipage/</a>
   <dt id="biblio-infra">[INFRA]
   <dd>Anne van Kesteren; Domenic Denicola. <a href="https://infra.spec.whatwg.org/">Infra Standard</a>. Living Standard. URL: <a href="https://infra.spec.whatwg.org/">https://infra.spec.whatwg.org/</a>
   <dt id="biblio-rfc2119">[RFC2119]
   <dd>S. Bradner. <a href="https://tools.ietf.org/html/rfc2119">Key words for use in RFCs to Indicate Requirement Levels</a>. March 1997. Best Current Practice. URL: <a href="https://tools.ietf.org/html/rfc2119">https://tools.ietf.org/html/rfc2119</a>
   <dt id="biblio-uievents">[UIEVENTS]
   <dd>Gary Kacmarcik; Travis Leithead; Doug Schepers. <a href="https://www.w3.org/TR/uievents/">UI Events</a>. 30 May 2019. WD. URL: <a href="https://www.w3.org/TR/uievents/">https://www.w3.org/TR/uievents/</a>
   <dt id="biblio-webidl">[WebIDL]
   <dd>Boris Zbarsky. <a href="https://heycam.github.io/webidl/">Web IDL</a>. 15 December 2016. ED. URL: <a href="https://heycam.github.io/webidl/">https://heycam.github.io/webidl/</a>
  </dl>
  <h3 class="no-num no-ref heading settled" id="informative"><span class="content">Informative References</span><a class="self-link" href="#informative"></a></h3>
  <dl>
   <dt id="biblio-css-transforms-1">[CSS-TRANSFORMS-1]
   <dd>Simon Fraser; et al. <a href="https://www.w3.org/TR/css-transforms-1/">CSS Transforms Module Level 1</a>. 14 February 2019. CR. URL: <a href="https://www.w3.org/TR/css-transforms-1/">https://www.w3.org/TR/css-transforms-1/</a>
   <dt id="biblio-extensible">[EXTENSIBLE]
   <dd><a href="https://extensiblewebmanifesto.org/">The Extensible Web Manifesto</a>. 10 June 2013. URL: <a href="https://extensiblewebmanifesto.org/">https://extensiblewebmanifesto.org/</a>
  </dl>
  <h2 class="no-num no-ref heading settled" id="property-index"><span class="content">Property Index</span><a class="self-link" href="#property-index"></a></h2>
  <div class="big-element-wrapper">
   <table class="index">
    <thead>
     <tr>
      <th scope="col">Name
      <th scope="col">Value
      <th scope="col">Initial
      <th scope="col">Applies to
      <th scope="col">Inh.
      <th scope="col">%ages
      <th scope="col">Anim­ation type
      <th scope="col">Canonical order
      <th scope="col">Com­puted value
    <tbody>
     <tr>
      <th scope="row"><a class="css" data-link-type="property" href="#propdef-spatial-navigation-action" id="ref-for-propdef-spatial-navigation-action①①">spatial-navigation-action</a>
      <td>auto | focus | scroll
      <td>auto
      <td>scroll containers
      <td>no
      <td>n/a
      <td>discrete
      <td>per grammar
      <td>as specified
     <tr>
      <th scope="row"><a class="css" data-link-type="property" href="#propdef-spatial-navigation-contain" id="ref-for-propdef-spatial-navigation-contain⑤">spatial-navigation-contain</a>
      <td>auto | contain
      <td>auto
      <td>all elements
      <td>no
      <td>n/a
      <td>discrete
      <td>per grammar
      <td>as specified
     <tr>
      <th scope="row"><a class="css" data-link-type="property" href="#propdef-spatial-navigation-function" id="ref-for-propdef-spatial-navigation-function③">spatial-navigation-function</a>
      <td>normal | grid
      <td>normal
      <td>spatial navigation containers
      <td>no
      <td>n/a
      <td>discrete
      <td>per grammar
      <td>as specified
   </table>
  </div>
  <h2 class="no-num no-ref heading settled" id="idl-index"><span class="content">IDL Index</span><a class="self-link" href="#idl-index"></a></h2>
<pre class="idl highlight def"><c- b>enum</c-> <a href="#enumdef-spatialnavigationdirection"><code><c- g>SpatialNavigationDirection</c-></code></a> {
    <a href="#dom-spatialnavigationdirection-up"><code><c- s>"up"</c-></code></a>,
    <a href="#dom-spatialnavigationdirection-down"><code><c- s>"down"</c-></code></a>,
    <a href="#dom-spatialnavigationdirection-left"><code><c- s>"left"</c-></code></a>,
    <a href="#dom-spatialnavigationdirection-right"><code><c- s>"right"</c-></code></a>,
};

<c- b>partial</c-> <c- b>interface</c-> <a class="idl-code" data-link-type="interface" href="https://html.spec.whatwg.org/multipage/window-object.html#window" id="ref-for-window①"><c- g>Window</c-></a> {
    <c- b>void</c-> <a class="idl-code" data-link-type="method" href="#dom-window-navigate" id="ref-for-dom-window-navigate①①"><c- g>navigate</c-></a>(<a class="n" data-link-type="idl-name" href="#enumdef-spatialnavigationdirection" id="ref-for-enumdef-spatialnavigationdirection④"><c- n>SpatialNavigationDirection</c-></a> <a href="#dom-window-navigate-dir-dir"><code><c- g>dir</c-></code></a>);
};

<c- b>enum</c-> <a href="#enumdef-focusableareasearchmode"><code><c- g>FocusableAreaSearchMode</c-></code></a> {
    <a href="#dom-focusableareasearchmode-visible"><code><c- s>"visible"</c-></code></a>,
    <a href="#dom-focusableareasearchmode-all"><code><c- s>"all"</c-></code></a>
};

<c- b>dictionary</c-> <a href="#dictdef-focusableareasoption"><code><c- g>FocusableAreasOption</c-></code></a> {
    <a class="n" data-link-type="idl-name" href="#enumdef-focusableareasearchmode" id="ref-for-enumdef-focusableareasearchmode①"><c- n>FocusableAreaSearchMode</c-></a> <a data-type="FocusableAreaSearchMode " href="#dom-focusableareasoption-mode"><code><c- g>mode</c-></code></a>;
};

<c- b>dictionary</c-> <a href="#dictdef-spatialnavigationsearchoptions"><code><c- g>SpatialNavigationSearchOptions</c-></code></a> {
    <c- b>sequence</c->&lt;<a class="n" data-link-type="idl-name" href="https://dom.spec.whatwg.org/#node" id="ref-for-node⑤"><c- n>Node</c-></a>>? <a data-type="sequence<Node>? " href="#dom-spatialnavigationsearchoptions-candidates"><code><c- g>candidates</c-></code></a>;
    <a class="n" data-link-type="idl-name" href="https://dom.spec.whatwg.org/#node" id="ref-for-node①①"><c- n>Node</c-></a>? <a data-type="Node? " href="#dom-spatialnavigationsearchoptions-container"><code><c- g>container</c-></code></a>;
};

<c- b>partial</c-> <c- b>interface</c-> <a class="idl-code" data-link-type="interface" href="https://dom.spec.whatwg.org/#element" id="ref-for-element①"><c- g>Element</c-></a> {
    <a class="n" data-link-type="idl-name" href="https://dom.spec.whatwg.org/#node" id="ref-for-node②①"><c- n>Node</c-></a> <a class="idl-code" data-link-type="method" href="#dom-element-getspatialnavigationcontainer" id="ref-for-dom-element-getspatialnavigationcontainer①①"><c- g>getSpatialNavigationContainer</c-></a>();
    <c- b>sequence</c->&lt;<a class="n" data-link-type="idl-name" href="https://dom.spec.whatwg.org/#node" id="ref-for-node③①"><c- n>Node</c-></a>> <a class="idl-code" data-link-type="method" href="#dom-element-focusableareas" id="ref-for-dom-element-focusableareas①①"><c- g>focusableAreas</c-></a>(<c- b>optional</c-> <a class="n" data-link-type="idl-name" href="#dictdef-focusableareasoption" id="ref-for-dictdef-focusableareasoption①"><c- n>FocusableAreasOption</c-></a> <a href="#dom-element-focusableareas-option-option"><code><c- g>option</c-></code></a>);
    <a class="n" data-link-type="idl-name" href="https://dom.spec.whatwg.org/#node" id="ref-for-node④①"><c- n>Node</c-></a>? <a href="#dom-element-spatialnavigationsearch"><code><c- g>spatialNavigationSearch</c-></code></a>(<a class="n" data-link-type="idl-name" href="#enumdef-spatialnavigationdirection" id="ref-for-enumdef-spatialnavigationdirection①①"><c- n>SpatialNavigationDirection</c-></a> <a href="#dom-element-spatialnavigationsearch-dir-options-dir"><code><c- g>dir</c-></code></a>, <c- b>optional</c-> <a class="n" data-link-type="idl-name" href="#dictdef-spatialnavigationsearchoptions" id="ref-for-dictdef-spatialnavigationsearchoptions②"><c- n>SpatialNavigationSearchOptions</c-></a> <a href="#dom-element-spatialnavigationsearch-dir-options-options"><code><c- g>options</c-></code></a>);
};

[<a class="idl-code" data-link-type="extended-attribute" href="https://heycam.github.io/webidl/#Exposed" id="ref-for-Exposed①"><c- g>Exposed</c-></a>=<c- n>Window</c->]
<c- b>interface</c-> <a href="#navigationevent"><code><c- g>NavigationEvent</c-></code></a> : <a class="n" data-link-type="idl-name" href="https://www.w3.org/TR/uievents/#uievent" id="ref-for-uievent①①"><c- n>UIEvent</c-></a> {
    <a href="#dom-navigationevent-navigationevent"><code><c- g>constructor</c-></code></a>(<a class="idl-code" data-link-type="interface" href="https://heycam.github.io/webidl/#idl-DOMString" id="ref-for-idl-DOMString①"><c- b>DOMString</c-></a> <a href="#dom-navigationevent-navigationevent-type-eventinitdict-type"><code><c- g>type</c-></code></a>,
                <c- b>optional</c-> <a class="n" data-link-type="idl-name" href="#dictdef-navigationeventinit" id="ref-for-dictdef-navigationeventinit①①"><c- n>NavigationEventInit</c-></a> <a href="#dom-navigationevent-navigationevent-type-eventinitdict-eventinitdict"><code><c- g>eventInitDict</c-></code></a>);
    <c- b>readonly</c-> <c- b>attribute</c-> <a class="n" data-link-type="idl-name" href="#enumdef-spatialnavigationdirection" id="ref-for-enumdef-spatialnavigationdirection②①"><c- n>SpatialNavigationDirection</c-></a> <a data-readonly data-type="SpatialNavigationDirection" href="#dom-navigationevent-dir"><code><c- g>dir</c-></code></a>;
    <c- b>readonly</c-> <c- b>attribute</c-> <a class="n" data-link-type="idl-name" href="https://dom.spec.whatwg.org/#eventtarget" id="ref-for-eventtarget②"><c- n>EventTarget</c-></a>? <a data-readonly data-type="EventTarget?" href="#dom-navigationevent-relatedtarget"><code><c- g>relatedTarget</c-></code></a>;
};

<c- b>dictionary</c-> <a href="#dictdef-navigationeventinit"><code><c- g>NavigationEventInit</c-></code></a> : <a class="n" data-link-type="idl-name" href="https://www.w3.org/TR/uievents/#dictdef-uieventinit" id="ref-for-dictdef-uieventinit①"><c- n>UIEventInit</c-></a> {
    <a class="n" data-link-type="idl-name" href="#enumdef-spatialnavigationdirection" id="ref-for-enumdef-spatialnavigationdirection③①"><c- n>SpatialNavigationDirection</c-></a> <a data-type="SpatialNavigationDirection " href="#dom-navigationeventinit-dir"><code><c- g>dir</c-></code></a>;
    <a class="n" data-link-type="idl-name" href="https://dom.spec.whatwg.org/#eventtarget" id="ref-for-eventtarget①①"><c- n>EventTarget</c-></a>? <a data-default="null" data-type="EventTarget? " href="#dom-navigationeventinit-relatedtarget"><code><c- g>relatedTarget</c-></code></a> = <c- b>null</c->;
};

</pre>
  <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content">Issues Index</span><a class="self-link" href="#issues-index"></a></h2>
  <div style="counter-reset:issue">
   <div class="issue"> The name of this API is under discussion <a href="https://github.com/w3c/csswg-drafts/issues/3387">&lt;https://github.com/w3c/csswg-drafts/issues/3387></a><a href="#issue-a5a227c8"> ↵ </a></div>
   <div class="issue"> CSS should have a term for “border box taking into account corner shaping properties like border-radius”. <a href="https://github.com/w3c/csswg-drafts/issues/2324">&lt;https://github.com/w3c/csswg-drafts/issues/2324></a><a href="#issue-c7f6d991"> ↵ </a></div>
   <div class="issue"> Terminology like this should be in <a data-link-type="biblio" href="#biblio-cssom-view-1">[CSSOM-VIEW-1]</a>, <a data-link-type="biblio" href="#biblio-css-overflow-3">[CSS-OVERFLOW-3]</a>, <a data-link-type="biblio" href="#biblio-css-scroll-snap-1">[CSS-SCROLL-SNAP-1]</a>. <a href="https://github.com/w3c/csswg-drafts/issues/2322">&lt;https://github.com/w3c/csswg-drafts/issues/2322></a><a href="#issue-942e7041"> ↵ </a></div>
   <div class="issue"> <a data-link-type="biblio" href="#biblio-cssom-view-1">[CSSOM-VIEW-1]</a> should probably define
how to perform a scroll in a given direction without an explicit position.
Until then, we roll our own. <a href="https://github.com/w3c/csswg-drafts/issues/2323">&lt;https://github.com/w3c/csswg-drafts/issues/2323></a><a href="#issue-00706fa4"> ↵ </a></div>
  </div>
  <aside class="dfn-panel" data-for="spatial-navigation">
   <b><a href="#spatial-navigation">#spatial-navigation</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-spatial-navigation">1. 
Introduction</a> <a href="#ref-for-spatial-navigation①">(2)</a> <a href="#ref-for-spatial-navigation②">(3)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="at-risk">
   <b><a href="#at-risk">#at-risk</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-at-risk">5.2. 
Low level APIs</a>
    <li><a href="#ref-for-at-risk①">9.1. 
Creating additional spatial navigation containers: the spatial-navigation-contain property</a>
    <li><a href="#ref-for-at-risk②">9.2. 
Controlling the interaction with scrolling: the spatial-navigation-action property</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="enumdef-spatialnavigationdirection">
   <b><a href="#enumdef-spatialnavigationdirection">#enumdef-spatialnavigationdirection</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-enumdef-spatialnavigationdirection">5.1. 
Triggering Navigation Programmatically</a>
    <li><a href="#ref-for-enumdef-spatialnavigationdirection①">5.2. 
Low level APIs</a>
    <li><a href="#ref-for-enumdef-spatialnavigationdirection②">6.1. 
Interface NavigationEvent</a> <a href="#ref-for-enumdef-spatialnavigationdirection③">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-spatialnavigationdirection-up">
   <b><a href="#dom-spatialnavigationdirection-up">#dom-spatialnavigationdirection-up</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-spatialnavigationdirection-up">8.4. 
Focus Navigation Heuristics</a> <a href="#ref-for-dom-spatialnavigationdirection-up①">(2)</a> <a href="#ref-for-dom-spatialnavigationdirection-up②">(3)</a> <a href="#ref-for-dom-spatialnavigationdirection-up③">(4)</a> <a href="#ref-for-dom-spatialnavigationdirection-up④">(5)</a> <a href="#ref-for-dom-spatialnavigationdirection-up⑤">(6)</a> <a href="#ref-for-dom-spatialnavigationdirection-up⑥">(7)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-spatialnavigationdirection-down">
   <b><a href="#dom-spatialnavigationdirection-down">#dom-spatialnavigationdirection-down</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-spatialnavigationdirection-down">8.4. 
Focus Navigation Heuristics</a> <a href="#ref-for-dom-spatialnavigationdirection-down①">(2)</a> <a href="#ref-for-dom-spatialnavigationdirection-down②">(3)</a> <a href="#ref-for-dom-spatialnavigationdirection-down③">(4)</a> <a href="#ref-for-dom-spatialnavigationdirection-down④">(5)</a> <a href="#ref-for-dom-spatialnavigationdirection-down⑤">(6)</a> <a href="#ref-for-dom-spatialnavigationdirection-down⑥">(7)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-spatialnavigationdirection-left">
   <b><a href="#dom-spatialnavigationdirection-left">#dom-spatialnavigationdirection-left</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-spatialnavigationdirection-left">8.4. 
Focus Navigation Heuristics</a> <a href="#ref-for-dom-spatialnavigationdirection-left①">(2)</a> <a href="#ref-for-dom-spatialnavigationdirection-left②">(3)</a> <a href="#ref-for-dom-spatialnavigationdirection-left③">(4)</a> <a href="#ref-for-dom-spatialnavigationdirection-left④">(5)</a> <a href="#ref-for-dom-spatialnavigationdirection-left⑤">(6)</a> <a href="#ref-for-dom-spatialnavigationdirection-left⑥">(7)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-spatialnavigationdirection-right">
   <b><a href="#dom-spatialnavigationdirection-right">#dom-spatialnavigationdirection-right</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-spatialnavigationdirection-right">8.4. 
Focus Navigation Heuristics</a> <a href="#ref-for-dom-spatialnavigationdirection-right①">(2)</a> <a href="#ref-for-dom-spatialnavigationdirection-right②">(3)</a> <a href="#ref-for-dom-spatialnavigationdirection-right③">(4)</a> <a href="#ref-for-dom-spatialnavigationdirection-right④">(5)</a> <a href="#ref-for-dom-spatialnavigationdirection-right⑤">(6)</a> <a href="#ref-for-dom-spatialnavigationdirection-right⑥">(7)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-window-navigate">
   <b><a href="#dom-window-navigate">#dom-window-navigate</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-window-navigate">5.1. 
Triggering Navigation Programmatically</a> <a href="#ref-for-dom-window-navigate①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="enumdef-focusableareasearchmode">
   <b><a href="#enumdef-focusableareasearchmode">#enumdef-focusableareasearchmode</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-enumdef-focusableareasearchmode">5.2. 
Low level APIs</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dictdef-focusableareasoption">
   <b><a href="#dictdef-focusableareasoption">#dictdef-focusableareasoption</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dictdef-focusableareasoption">5.2. 
Low level APIs</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-focusableareasoption-mode">
   <b><a href="#dom-focusableareasoption-mode">#dom-focusableareasoption-mode</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-focusableareasoption-mode">5.2. 
Low level APIs</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dictdef-spatialnavigationsearchoptions">
   <b><a href="#dictdef-spatialnavigationsearchoptions">#dictdef-spatialnavigationsearchoptions</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dictdef-spatialnavigationsearchoptions">5.2. 
Low level APIs</a>
    <li><a href="#ref-for-dictdef-spatialnavigationsearchoptions①">Changes</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-spatialnavigationsearchoptions-candidates">
   <b><a href="#dom-spatialnavigationsearchoptions-candidates">#dom-spatialnavigationsearchoptions-candidates</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-spatialnavigationsearchoptions-candidates">5.2. 
Low level APIs</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-spatialnavigationsearchoptions-container">
   <b><a href="#dom-spatialnavigationsearchoptions-container">#dom-spatialnavigationsearchoptions-container</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-spatialnavigationsearchoptions-container">5.2. 
Low level APIs</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-element-spatialnavigationsearch">
   <b><a href="#dom-element-spatialnavigationsearch">#dom-element-spatialnavigationsearch</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-element-spatialnavigationsearch">Changes</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-element-getspatialnavigationcontainer">
   <b><a href="#dom-element-getspatialnavigationcontainer">#dom-element-getspatialnavigationcontainer</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-element-getspatialnavigationcontainer①">5.2. 
Low level APIs</a> <a href="#ref-for-dom-element-getspatialnavigationcontainer②">(2)</a> <a href="#ref-for-dom-element-getspatialnavigationcontainer③">(3)</a>
    <li><a href="#ref-for-dom-element-getspatialnavigationcontainer④">Changes</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-element-focusableareas">
   <b><a href="#dom-element-focusableareas">#dom-element-focusableareas</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-element-focusableareas①">5.2. 
Low level APIs</a> <a href="#ref-for-dom-element-focusableareas②">(2)</a> <a href="#ref-for-dom-element-focusableareas③">(3)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="navigationevent">
   <b><a href="#navigationevent">#navigationevent</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-navigationevent">4. 
Triggering Spatial Navigation</a>
    <li><a href="#ref-for-navigationevent①">6.1. 
Interface NavigationEvent</a> <a href="#ref-for-navigationevent②">(2)</a> <a href="#ref-for-navigationevent③">(3)</a>
    <li><a href="#ref-for-navigationevent④">6.2.1. 
navbeforefocus</a> <a href="#ref-for-navigationevent⑤">(2)</a> <a href="#ref-for-navigationevent⑥">(3)</a>
    <li><a href="#ref-for-navigationevent⑦">6.2.2. 
navnotarget</a> <a href="#ref-for-navigationevent⑧">(2)</a> <a href="#ref-for-navigationevent⑨">(3)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-navigationevent-dir">
   <b><a href="#dom-navigationevent-dir">#dom-navigationevent-dir</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-navigationevent-dir">6.2.1. 
navbeforefocus</a>
    <li><a href="#ref-for-dom-navigationevent-dir①">6.2.2. 
navnotarget</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-navigationevent-relatedtarget">
   <b><a href="#dom-navigationevent-relatedtarget">#dom-navigationevent-relatedtarget</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-navigationevent-relatedtarget">6.2.1. 
navbeforefocus</a> <a href="#ref-for-dom-navigationevent-relatedtarget①">(2)</a>
    <li><a href="#ref-for-dom-navigationevent-relatedtarget②">6.2.2. 
navnotarget</a> <a href="#ref-for-dom-navigationevent-relatedtarget③">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dictdef-navigationeventinit">
   <b><a href="#dictdef-navigationeventinit">#dictdef-navigationeventinit</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dictdef-navigationeventinit">6.1. 
Interface NavigationEvent</a> <a href="#ref-for-dictdef-navigationeventinit①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="eventdef-navigationevent-navbeforefocus">
   <b><a href="#eventdef-navigationevent-navbeforefocus">#eventdef-navigationevent-navbeforefocus</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-eventdef-navigationevent-navbeforefocus">6.2.1. 
navbeforefocus</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dispatches-navbeforefocus-event">
   <b><a href="#dispatches-navbeforefocus-event">#dispatches-navbeforefocus-event</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dispatches-navbeforefocus-event">8.3. 
Navigation</a> <a href="#ref-for-dispatches-navbeforefocus-event①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="eventdef-navigationevent-navnotarget">
   <b><a href="#eventdef-navigationevent-navnotarget">#eventdef-navigationevent-navnotarget</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-eventdef-navigationevent-navnotarget">6.2.2. 
navnotarget</a>
    <li><a href="#ref-for-eventdef-navigationevent-navnotarget①">9.2. 
Controlling the interaction with scrolling: the spatial-navigation-action property</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dispatches-navnotarget-event">
   <b><a href="#dispatches-navnotarget-event">#dispatches-navnotarget-event</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dispatches-navnotarget-event">8.3. 
Navigation</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="navigation-override">
   <b><a href="#navigation-override">#navigation-override</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-navigation-override">6.2.1. 
navbeforefocus</a>
    <li><a href="#ref-for-navigation-override①">6.2.2. 
navnotarget</a>
    <li><a href="#ref-for-navigation-override②">7. 
The navigation-override policy-controlled feature</a> <a href="#ref-for-navigation-override③">(2)</a> <a href="#ref-for-navigation-override④">(3)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="boundary-box">
   <b><a href="#boundary-box">#boundary-box</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-boundary-box">8.1. 
Glossary</a>
    <li><a href="#ref-for-boundary-box①">8.4. 
Focus Navigation Heuristics</a> <a href="#ref-for-boundary-box②">(2)</a> <a href="#ref-for-boundary-box③">(3)</a> <a href="#ref-for-boundary-box④">(4)</a> <a href="#ref-for-boundary-box⑤">(5)</a> <a href="#ref-for-boundary-box⑥">(6)</a> <a href="#ref-for-boundary-box⑦">(7)</a> <a href="#ref-for-boundary-box⑧">(8)</a> <a href="#ref-for-boundary-box⑨">(9)</a> <a href="#ref-for-boundary-box①⓪">(10)</a> <a href="#ref-for-boundary-box①①">(11)</a> <a href="#ref-for-boundary-box①②">(12)</a> <a href="#ref-for-boundary-box①③">(13)</a> <a href="#ref-for-boundary-box①④">(14)</a> <a href="#ref-for-boundary-box①⑤">(15)</a> <a href="#ref-for-boundary-box①⑥">(16)</a> <a href="#ref-for-boundary-box①⑦">(17)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="inside-area">
   <b><a href="#inside-area">#inside-area</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-inside-area">8.1. 
Glossary</a>
    <li><a href="#ref-for-inside-area①">8.4. 
Focus Navigation Heuristics</a> <a href="#ref-for-inside-area②">(2)</a> <a href="#ref-for-inside-area③">(3)</a> <a href="#ref-for-inside-area④">(4)</a> <a href="#ref-for-inside-area⑤">(5)</a> <a href="#ref-for-inside-area⑥">(6)</a> <a href="#ref-for-inside-area⑦">(7)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="search-origin">
   <b><a href="#search-origin">#search-origin</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-search-origin">8.4. 
Focus Navigation Heuristics</a> <a href="#ref-for-search-origin①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="spatial-navigation-starting-point">
   <b><a href="#spatial-navigation-starting-point">#spatial-navigation-starting-point</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-spatial-navigation-starting-point">8.1. 
Glossary</a>
    <li><a href="#ref-for-spatial-navigation-starting-point①">8.4. 
Focus Navigation Heuristics</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="spatial-navigation-containers">
   <b><a href="#spatial-navigation-containers">#spatial-navigation-containers</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-spatial-navigation-containers">3. 
Overview</a> <a href="#ref-for-spatial-navigation-containers①">(2)</a> <a href="#ref-for-spatial-navigation-containers②">(3)</a> <a href="#ref-for-spatial-navigation-containers③">(4)</a> <a href="#ref-for-spatial-navigation-containers④">(5)</a> <a href="#ref-for-spatial-navigation-containers⑤">(6)</a> <a href="#ref-for-spatial-navigation-containers⑥">(7)</a> <a href="#ref-for-spatial-navigation-containers⑦">(8)</a>
    <li><a href="#ref-for-spatial-navigation-containers⑧">5.2. 
Low level APIs</a> <a href="#ref-for-spatial-navigation-containers⑨">(2)</a> <a href="#ref-for-spatial-navigation-containers①⓪">(3)</a> <a href="#ref-for-spatial-navigation-containers①①">(4)</a> <a href="#ref-for-spatial-navigation-containers①②">(5)</a> <a href="#ref-for-spatial-navigation-containers①③">(6)</a> <a href="#ref-for-spatial-navigation-containers①④">(7)</a> <a href="#ref-for-spatial-navigation-containers①⑤">(8)</a> <a href="#ref-for-spatial-navigation-containers①⑥">(9)</a>
    <li><a href="#ref-for-spatial-navigation-containers①⑦">6.2.2. 
navnotarget</a> <a href="#ref-for-spatial-navigation-containers①⑧">(2)</a> <a href="#ref-for-spatial-navigation-containers①⑨">(3)</a> <a href="#ref-for-spatial-navigation-containers②⓪">(4)</a> <a href="#ref-for-spatial-navigation-containers②①">(5)</a> <a href="#ref-for-spatial-navigation-containers②②">(6)</a> <a href="#ref-for-spatial-navigation-containers②③">(7)</a>
    <li><a href="#ref-for-spatial-navigation-containers②④">8.2. 
Groupings of elements</a> <a href="#ref-for-spatial-navigation-containers②⑤">(2)</a>
    <li><a href="#ref-for-spatial-navigation-containers②⑥">8.3. 
Navigation</a> <a href="#ref-for-spatial-navigation-containers②⑦">(2)</a> <a href="#ref-for-spatial-navigation-containers②⑧">(3)</a>
    <li><a href="#ref-for-spatial-navigation-containers②⑨">8.4. 
Focus Navigation Heuristics</a>
    <li><a href="#ref-for-spatial-navigation-containers③⓪">9.1. 
Creating additional spatial navigation containers: the spatial-navigation-contain property</a> <a href="#ref-for-spatial-navigation-containers③①">(2)</a> <a href="#ref-for-spatial-navigation-containers③②">(3)</a>
    <li><a href="#ref-for-spatial-navigation-containers③③">9.2. 
Controlling the interaction with scrolling: the spatial-navigation-action property</a>
    <li><a href="#ref-for-spatial-navigation-containers③④">9.3. 
Selecting the navigation algorithm: the spatial-navigation-function property</a> <a href="#ref-for-spatial-navigation-containers③⑤">(2)</a>
    <li><a href="#ref-for-spatial-navigation-containers③⑥">Changes</a> <a href="#ref-for-spatial-navigation-containers③⑦">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="spatial-navigation-steps">
   <b><a href="#spatial-navigation-steps">#spatial-navigation-steps</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-spatial-navigation-steps">4. 
Triggering Spatial Navigation</a> <a href="#ref-for-spatial-navigation-steps①">(2)</a> <a href="#ref-for-spatial-navigation-steps②">(3)</a>
    <li><a href="#ref-for-spatial-navigation-steps③">5.1. 
Triggering Navigation Programmatically</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="set-the-search-origin">
   <b><a href="#set-the-search-origin">#set-the-search-origin</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-set-the-search-origin">8.3. 
Navigation</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="update-the-search-origin">
   <b><a href="#update-the-search-origin">#update-the-search-origin</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-update-the-search-origin">8.4. 
Focus Navigation Heuristics</a>
    <li><a href="#ref-for-update-the-search-origin①">Changes</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="find-focusable-areas">
   <b><a href="#find-focusable-areas">#find-focusable-areas</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-find-focusable-areas">5.2. 
Low level APIs</a> <a href="#ref-for-find-focusable-areas①">(2)</a>
    <li><a href="#ref-for-find-focusable-areas②">8.3. 
Navigation</a> <a href="#ref-for-find-focusable-areas③">(2)</a>
    <li><a href="#ref-for-find-focusable-areas④">8.4. 
Focus Navigation Heuristics</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="select-the-best-candidate">
   <b><a href="#select-the-best-candidate">#select-the-best-candidate</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-select-the-best-candidate">5.2. 
Low level APIs</a>
    <li><a href="#ref-for-select-the-best-candidate①">6.2.1. 
navbeforefocus</a>
    <li><a href="#ref-for-select-the-best-candidate②">8.3. 
Navigation</a> <a href="#ref-for-select-the-best-candidate③">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="find-the-shortest-distance">
   <b><a href="#find-the-shortest-distance">#find-the-shortest-distance</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-find-the-shortest-distance">8.4. 
Focus Navigation Heuristics</a>
    <li><a href="#ref-for-find-the-shortest-distance①">9.3. 
Selecting the navigation algorithm: the spatial-navigation-function property</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="propdef-spatial-navigation-contain">
   <b><a href="#propdef-spatial-navigation-contain">#propdef-spatial-navigation-contain</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-propdef-spatial-navigation-contain①">3. 
Overview</a>
    <li><a href="#ref-for-propdef-spatial-navigation-contain②">8.2. 
Groupings of elements</a>
    <li><a href="#ref-for-propdef-spatial-navigation-contain③">9.1. 
Creating additional spatial navigation containers: the spatial-navigation-contain property</a> <a href="#ref-for-propdef-spatial-navigation-contain④">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="propdef-spatial-navigation-action">
   <b><a href="#propdef-spatial-navigation-action">#propdef-spatial-navigation-action</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-propdef-spatial-navigation-action①">8.3. 
Navigation</a> <a href="#ref-for-propdef-spatial-navigation-action②">(2)</a> <a href="#ref-for-propdef-spatial-navigation-action③">(3)</a> <a href="#ref-for-propdef-spatial-navigation-action④">(4)</a> <a href="#ref-for-propdef-spatial-navigation-action⑤">(5)</a> <a href="#ref-for-propdef-spatial-navigation-action⑥">(6)</a>
    <li><a href="#ref-for-propdef-spatial-navigation-action⑦">9.2. 
Controlling the interaction with scrolling: the spatial-navigation-action property</a> <a href="#ref-for-propdef-spatial-navigation-action⑧">(2)</a> <a href="#ref-for-propdef-spatial-navigation-action⑨">(3)</a> <a href="#ref-for-propdef-spatial-navigation-action①⓪">(4)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="valdef-spatial-navigation-action-auto">
   <b><a href="#valdef-spatial-navigation-action-auto">#valdef-spatial-navigation-action-auto</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-valdef-spatial-navigation-action-auto">8.3. 
Navigation</a>
    <li><a href="#ref-for-valdef-spatial-navigation-action-auto①">9.2. 
Controlling the interaction with scrolling: the spatial-navigation-action property</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="valdef-spatial-navigation-action-focus">
   <b><a href="#valdef-spatial-navigation-action-focus">#valdef-spatial-navigation-action-focus</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-valdef-spatial-navigation-action-focus">8.3. 
Navigation</a> <a href="#ref-for-valdef-spatial-navigation-action-focus①">(2)</a> <a href="#ref-for-valdef-spatial-navigation-action-focus②">(3)</a> <a href="#ref-for-valdef-spatial-navigation-action-focus③">(4)</a>
    <li><a href="#ref-for-valdef-spatial-navigation-action-focus④">9.2. 
Controlling the interaction with scrolling: the spatial-navigation-action property</a> <a href="#ref-for-valdef-spatial-navigation-action-focus⑤">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="valdef-spatial-navigation-action-scroll">
   <b><a href="#valdef-spatial-navigation-action-scroll">#valdef-spatial-navigation-action-scroll</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-valdef-spatial-navigation-action-scroll">8.3. 
Navigation</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="propdef-spatial-navigation-function">
   <b><a href="#propdef-spatial-navigation-function">#propdef-spatial-navigation-function</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-propdef-spatial-navigation-function①">9.3. 
Selecting the navigation algorithm: the spatial-navigation-function property</a>
    <li><a href="#ref-for-propdef-spatial-navigation-function②">Changes</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="can-be-manually-scrolled">
   <b><a href="#can-be-manually-scrolled">#can-be-manually-scrolled</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-can-be-manually-scrolled">8.3. 
Navigation</a> <a href="#ref-for-can-be-manually-scrolled①">(2)</a> <a href="#ref-for-can-be-manually-scrolled②">(3)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="directionally-scroll-an-element">
   <b><a href="#directionally-scroll-an-element">#directionally-scroll-an-element</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-directionally-scroll-an-element">8.3. 
Navigation</a> <a href="#ref-for-directionally-scroll-an-element①">(2)</a> <a href="#ref-for-directionally-scroll-an-element②">(3)</a>
    <li><a href="#ref-for-directionally-scroll-an-element③">9.2. 
Controlling the interaction with scrolling: the spatial-navigation-action property</a>
   </ul>
  </aside>
<script>/* script-var-click-highlighting */

    document.addEventListener("click", e=>{
        if(e.target.nodeName == "VAR") {
            highlightSameAlgoVars(e.target);
        }
    });
    {
        const indexCounts = new Map();
        const indexNames = new Map();
        function highlightSameAlgoVars(v) {
            // Find the algorithm container.
            let algoContainer = null;
            let searchEl = v;
            while(algoContainer == null && searchEl != document.body) {
                searchEl = searchEl.parentNode;
                if(searchEl.hasAttribute("data-algorithm")) {
                    algoContainer = searchEl;
                }
            }

            // Not highlighting document-global vars,
            // too likely to be unrelated.
            if(algoContainer == null) return;

            const algoName = algoContainer.getAttribute("data-algorithm");
            const varName = getVarName(v);
            const addClass = !v.classList.contains("selected");
            let highlightClass = null;
            if(addClass) {
                const index = chooseHighlightIndex(algoName, varName);
                indexCounts.get(algoName)[index] += 1;
                indexNames.set(algoName+"///"+varName, index);
                highlightClass = nameFromIndex(index);
            } else {
                const index = previousHighlightIndex(algoName, varName);
                indexCounts.get(algoName)[index] -= 1;
                highlightClass = nameFromIndex(index);
            }

            // Find all same-name vars, and toggle their class appropriately.
            for(const el of algoContainer.querySelectorAll("var")) {
                if(getVarName(el) == varName) {
                    el.classList.toggle("selected", addClass);
                    el.classList.toggle(highlightClass, addClass);
                }
            }
        }
        function getVarName(el) {
            return el.textContent.replace(/(\s| )+/, " ").trim();
        }
        function chooseHighlightIndex(algoName, varName) {
            let indexes = null;
            if(indexCounts.has(algoName)) {
                indexes = indexCounts.get(algoName);
            } else {
                // 7 classes right now
                indexes = [0,0,0,0,0,0,0];
                indexCounts.set(algoName, indexes);
            }

            // If the element was recently unclicked,
            // *and* that color is still unclaimed,
            // give it back the same color.
            const lastIndex = previousHighlightIndex(algoName, varName);
            if(indexes[lastIndex] === 0) return lastIndex;

            // Find the earliest index with the lowest count.
            const minCount = Math.min.apply(null, indexes);
            let index = null;
            for(var i = 0; i < indexes.length; i++) {
                if(indexes[i] == minCount) {
                    return i;
                }
            }
        }
        function previousHighlightIndex(algoName, varName) {
            return indexNames.get(algoName+"///"+varName);
        }
        function nameFromIndex(index) {
            return "selected" + index;
        }
    }
    </script>
<script>/* script-dfn-panel */

document.body.addEventListener("click", function(e) {
    var queryAll = function(sel) { return [].slice.call(document.querySelectorAll(sel)); }
    // Find the dfn element or panel, if any, that was clicked on.
    var el = e.target;
    var target;
    var hitALink = false;
    while(el.parentElement) {
        if(el.tagName == "A") {
            // Clicking on a link in a <dfn> shouldn't summon the panel
            hitALink = true;
        }
        if(el.classList.contains("dfn-paneled")) {
            target = "dfn";
            break;
        }
        if(el.classList.contains("dfn-panel")) {
            target = "dfn-panel";
            break;
        }
        el = el.parentElement;
    }
    if(target != "dfn-panel") {
        // Turn off any currently "on" or "activated" panels.
        queryAll(".dfn-panel.on, .dfn-panel.activated").forEach(function(el){
            el.classList.remove("on");
            el.classList.remove("activated");
        });
    }
    if(target == "dfn" && !hitALink) {
        // open the panel
        var dfnPanel = document.querySelector(".dfn-panel[data-for='" + el.id + "']");
        if(dfnPanel) {
            dfnPanel.classList.add("on");
            var rect = el.getBoundingClientRect();
            dfnPanel.style.left = window.scrollX + rect.right + 5 + "px";
            dfnPanel.style.top = window.scrollY + rect.top + "px";
            var panelRect = dfnPanel.getBoundingClientRect();
            var panelWidth = panelRect.right - panelRect.left;
            if(panelRect.right > document.body.scrollWidth && (rect.left - (panelWidth + 5)) > 0) {
                // Reposition, because the panel is overflowing
                dfnPanel.style.left = window.scrollX + rect.left - (panelWidth + 5) + "px";
            }
        } else {
            console.log("Couldn't find .dfn-panel[data-for='" + el.id + "']");
        }
    } else if(target == "dfn-panel") {
        // Switch it to "activated" state, which pins it.
        el.classList.add("activated");
        el.style.left = null;
        el.style.top = null;
    }

});
</script>